Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support renaming enum variants #3383

Closed
DataTriny opened this issue Aug 13, 2023 · 0 comments · Fixed by #3384
Closed

Support renaming enum variants #3383

DataTriny opened this issue Aug 13, 2023 · 0 comments · Fixed by #3384

Comments

@DataTriny
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant