You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be really convenient if the #[pyclass] attribute offered a way to rename all variants of an enum.
The problem
By default the generated Python enums expose variants named after Rust's naming convention, which is not idiomatic for Python where SCREAMING_SNAKE_CASE is the norm. One can either create a new enum specifically tailored for PyO3, or apply #[pyo3(name = "...")] to every variants. Neither of these options are practical for big enums, and I can't make the second one work if I need to conditionally support PyO3: #[cfg_attr(feature = "pyo3", pyo3(name = "...")] won't compile.
Solution
Add a new argument to #[pyclass] that would only apply to enums and that would rename all their variants: rename_all for instance.
It could be a good idea to also support #[serde(rename_all = "...")] if it is already applied to an enum, although I don't think it would happen often that people use screaming snake case when (de)serializing their types.
The text was updated successfully, but these errors were encountered:
It would be really convenient if the
#[pyclass]
attribute offered a way to rename all variants of an enum.The problem
By default the generated Python enums expose variants named after Rust's naming convention, which is not idiomatic for Python where SCREAMING_SNAKE_CASE is the norm. One can either create a new enum specifically tailored for PyO3, or apply
#[pyo3(name = "...")]
to every variants. Neither of these options are practical for big enums, and I can't make the second one work if I need to conditionally support PyO3:#[cfg_attr(feature = "pyo3", pyo3(name = "...")]
won't compile.Solution
Add a new argument to
#[pyclass]
that would only apply to enums and that would rename all their variants:rename_all
for instance.It could be a good idea to also support
#[serde(rename_all = "...")]
if it is already applied to an enum, although I don't think it would happen often that people use screaming snake case when (de)serializing their types.The text was updated successfully, but these errors were encountered: