| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| if enum: | ||
| assert not isinstance(value, enum.Enum) | ||
| assert value.name == name | ||
| assert value.value == raw_value |
There was a problem hiding this comment.
Self-note: Should try to implement Flag based interface. (i.e. closure under arithmetic operations)
Sorry, something went wrong.
| return iter(cls.__members__.values()) | ||
|
|
||
| def __len__(cls): | ||
| return len(cls.__members__) |
There was a problem hiding this comment.
Sorry, didn't realize this should be done in enum.EnumMeta, not here. 🤦
Is there a way to do it without altering builtin classes?
Sorry, something went wrong.
There was a problem hiding this comment.
Not that I'm aware of :( I had gone the route of modifying builtin classes, but yuck:
master...a41944c
(I didn't get it fully working, hit some weird recursion thing, and gave up 'cause ewww)
Sorry, something went wrong.
There was a problem hiding this comment.
I agree, it does look too hacky and doesn't sound like right thing to do.
Actually pybind-enum is NOT enum.Enum, so maybe we shouldn't try to make this check return true? I think it would be more appropriate to introduce collections.abc.Enum (e.g. in python 3.10) and make isinstance(pybind_enum_value, colletions.abc.Enum) recognize all PEP-complaining enum implementations? In meantime one probably have no choice other than stick to self-written check method (like one in tests in this PR).
I think such doubtful hacks would greatly reduce the PR merge chances, so I would leave attempts to introduce them, at least for now.
Sorry, something went wrong.
|
Urgh, I didn't realize this would be so much harder than it seems, when reading the original comments in #2332 :-| |
Sorry, something went wrong.
Yeah lol, gotta get them meta classes in :( |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Description
(Currently draft)
Resolves #2332
Duck-type, but does not support isinstance(pybind11_enum_value, enum.Enum).
Suggested changelog entry: