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

Allow module= attribute in complex enum variants #4228

Merged
merged 5 commits into from
Jun 3, 2024

Conversation

liammcinroy
Copy link
Contributor

@liammcinroy liammcinroy commented Jun 2, 2024

Allows use of the module attribute for complex enum variants (but not simple enums), like

#[pyclass(module = "custom_module"]
enum Complex {
    #[pyo3(module = "custom_module")]
    Variant(),
}

so that Complex.Variant.__module__ == "custom_module" instead of builtins

Useful to allow pickling (and introspection in general) for complex enums (as noted in #1517 (comment)).

@davidhewitt
Copy link
Member

Thanks for the PR! I wonder, is there any case where users want the module of the variant to be different to the whole enum?

My feeling is no, in which case maybe it's better if we propagate the module from the enum onto all the variants...

@liammcinroy
Copy link
Contributor Author

@davidhewitt That was also my original feeling (at least, while the variants are still added to the same module as the whole enum). It is an even simpler PR then as well! latest commit has that change

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@davidhewitt davidhewitt added this pull request to the merge queue Jun 3, 2024
Merged via the queue into PyO3:main with commit b4b780b Jun 3, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants