-
Notifications
You must be signed in to change notification settings - Fork 2.2k
enum_ QoL improvements and enum.IntEnum #530
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
Comments
And finally (of course):
|
Hi @aldanor, this sounds generally reasonable, except for two parts:
Wenzel |
It also doesn't exist in the standard library before Python 3.4 -- however, there's That being said, if you're compiling a pybind11 extension for Python 3.4-3.5-3.6, you already know that
Could you elaborate on that?
I don't think we can make a switch (because Python 2 / <3.4) unless we ship the backport with pybind, so it would likely be an additional feature if we decide on it (e.g. |
Aha, I assumed that you proposed to replace |
@wjakob @jagerman Given recent interest in this, I could get on to implementing it. If I remember correctly, there were two questions I couldn't answer back then: what's the best way to dynamically (no template specialization) register a type caster for a Python type that has not been created via pybind machinery? Functionally, it would be like the example above, with casting/loading working both ways. The second question is -- once the type is created, where to store it? (in the example above, you see the |
Just a note in passing: Py3.6 introduced enum.Flag and enum.IntFlag (https://docs.python.org/3/library/enum.html#intflag), which are Python-level enums which support bitwise-operations with a nice repr. It would be appreciated if pybind11 could optionally represent enums using Flag and IntFlag as well. |
Since #781 got closed, we can close this issue as well. |
Although the original PR got closed, I think that it is still worth aiming to resolve this issue. Some discussion would need to happen around exactly how it would get implemented. |
I've been using Python 3
enum.IntEnum
lately instead of pybind11enum_<>
enums (although they're less straightforward to bind), since the former are (a) faster and (b) more ergonomic/Pythonic.I wonder if we could either improve
enum_
a little (a lot?), and/or provide a shortcut to bind standard library enums on Python 3?I'll try to prove my point using this mini-example:
enum.IntEnum
type:enum_
values:enum.IntEnum
values:The text was updated successfully, but these errors were encountered: