Repository navigation
Mixin repr overrides Enum repr in some cases #83768
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
rmccampbell7 commented
on Feb 8, 2020 rmccampbell7mannequinMannequinAuthorMore actionsIn Python 3.6 the following works:
class HexInt(int): def __repr__(self): return hex(self) class MyEnum(HexInt, enum.Enum): A = 1 B = 2 C = 3
>>> MyEnum.A <MyEnum.A: 0x1> However in Python 3.7/8 it instead prints >>> MyEnum.A 0x1
It uses HexInt's repr instead of Enum's. Looking at the enum.py module it seems that this occurs for mixin classes that don't define __new__ due to a change in the _get_mixins_ method. If I define a __new__ method on the HexInt class then the expected behavior occurs.
- added3.7 (EOL)end of lifeend of life3.8 (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 Feb 8, 2020 Bisecting points to bpo-29577 that introduced this change.
- added3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifeand removed3.7 (EOL)end of lifeend of life
on Sep 15, 2020 Yes, the change only considered types with their own copy of
__new__to be actual data types, so in 3.6HexIntwas the recognized data type, but in 3.7+ it wasint-- which also meant that HexEnum was considered a simple mix-in and its__repr__was used instead ofEnum.__repr__.
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: