Support `Boost.Python.enum` Enums as annotation and supported type.
Daraan opened this issue · comments
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.
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...)