Repository navigation
enum: Mixin and int base class regression in 3.8.6 #86055
Copy link
Copy link
Closed
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
The following code worked in 3.8.5 but does not in 3.8.6 due to the fix for bpo-39587:
import enum class MyInt(int): def __new__(cls, value): return super().__new__(cls, value) class HexMixin: def __repr__(self): return hex(self) class MyIntEnum(HexMixin, MyInt, enum.Enum): pass class Foo(MyIntEnum): TEST = 1 assert isinstance(Foo.TEST, MyInt) assert repr(Foo.TEST) == "0x1"In 3.8.6, the
Fooenum itself fails to be created becauseHexMixinis now considered the member type instead ofMyInt:Traceback (most recent call last): File "enum_test.py", line 18, in <module> class Foo(MyIntEnum): File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/enum.py", line 215, in __new__ enum_member = __new__(enum_class) TypeError: object.__new__(Foo) is not safe, use int.__new__()- added3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Sep 30, 2020 Actually, this is an issue with native types in general that define a 'tp_new' slot value ('!= NULL').
Metadata
Metadata
Assignees
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: