-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
3.11.5 Regression: Flags with custom __new__ can't be iterated #108682
Comments
This ended up being a combination of user error, program error, and some not-detailed-enough documentation. An
or, if using an already defined enum type (i.e.
The code has been updated to raise a |
@ziima: the correct fix for your code:
which works across all Python versions. |
Works like a charm, thanks @ethanfurman. I think I actually tried that, but I may had had other error in there at that moment. |
… __new__ (GH-108704) When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. . member = object.__new__(cls) member = int.__new__(cls, value) member = str.__new__(cls, value) Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected.
…custom __new__ (pythonGH-108704) When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. . member = object.__new__(cls) member = int.__new__(cls, value) member = str.__new__(cls, value) Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected. (cherry picked from commit d48760b) Co-authored-by: Ethan Furman <[email protected]>
… custom __new__ (GH-108704) (#108733) gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704) When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. . member = object.__new__(cls) member = int.__new__(cls, value) member = str.__new__(cls, value) Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected. (cherry picked from commit d48760b) Co-authored-by: Ethan Furman <[email protected]>
…custom __new__ (pythonGH-108704) When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. . member = object.__new__(cls) member = int.__new__(cls, value) member = str.__new__(cls, value) Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected. (cherry picked from commit d48760b)
Seems to be a breaking change. Not something would have expected in an Haven't had the time to look at it more closely, but noticed our test suite failing once again after it had been fixed for |
… custom __new__ (GH-108704) (GH-108739) When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. . member = object.__new__(cls) member = int.__new__(cls, value) member = str.__new__(cls, value) Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected. (cherry picked from commit d48760b)
For posterity: the issue is that zigpy has empty enums, but uses a custom The solution for zigpy is to move the desired behavior into a custom metaclass. |
Bug report
Checklist
and am confident this bug has not been reported before
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.11.5 (main, Aug 25 2023, 23:47:33) [GCC 12.2.0]
A clear and concise description of the bug:
A behavior of
Flag
changed in python 3.11.5. WhenFlag
with custom__new__
is used in combination with functional API, it's members can't be retrieved by iteration over the class.MWE:
The output in python 3.11.4:
The output in python 3.11.5:
I suspect this commit to introduce the regression: 59f009e
A workaround for 3.11.5:
Linked PRs
The text was updated successfully, but these errors were encountered: