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 Boost.Python.enum Enums as annotation and supported type. #1160

Open
Daraan opened this issue Feb 28, 2024 · 1 comment
Open

Support Boost.Python.enum Enums as annotation and supported type. #1160

Daraan opened this issue Feb 28, 2024 · 1 comment

Comments

@Daraan
Copy link

Daraan commented Feb 28, 2024

Is your feature request related to a problem? Please describe.
When an Enum is implemented in C++ and brought to Python via the Boost.Python.enum class is not supported like normal Enums despite being alike.

flags=dict(allow_objects=True) needs to be used to allow these Enum type hints, however there will then be no safeguarding and any value can be written into these fields.
Further Union cannot used with them.

Describe the solution you'd like
Boost.Python.enum should possible as type like the standard Python Enums


A workaround is to construct a intermediate enum.
One would need to reconstruct all enums by hand or use the functional approach:

DummyEnum = Enum("DummyEnum", {str(name):value for value, name in RealEnum.values.items()})

@dataclass
class Mine():
    greeting: DummyEnum = RealEnum.HELLO # type: ignore

However the functional approach does not allow for correct type hints here.

@odelalleau
Copy link
Collaborator

This seems like a niche use case that is unlikely to ever get supported unless someone who really needs it submits a complete PR for it. Also unless Boost.Python.enum is a subclass of enum.Enum this may require a lot of changes in the code (and if it is I'm not 100% sure how easy it'd be...)

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

No branches or pull requests

2 participants