You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mixin repr overrides Enum repr in some cases #83768
>>> 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.
Yes, the change only considered types with their own copy of __new__ to be actual data types, so in 3.6 HexInt was the recognized data type, but in 3.7+ it was int -- which also meant that HexEnum was considered a simple mix-in and its __repr__ was used instead of Enum.__repr__.
Activity
rmccampbell7 commentedon Feb 8, 2020
In Python 3.6 the following works:
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.
tirkarthi commentedon Feb 10, 2020
Bisecting points to bpo-29577 that introduced this change.
ethanfurman commentedon 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__.ethanfurman commentedon Sep 15, 2020
New changeset bff01f3 by Ethan Furman in branch 'master':
bpo-39587: Enum - use correct mixed-in data type (GH-22263)
bff01f3
miss-islington commentedon Sep 15, 2020
New changeset 8f8ebcc by Miss Islington (bot) in branch '3.8':
bpo-39587: Enum - use correct mixed-in data type (GH-22263)
8f8ebcc
ethanfurman commentedon Sep 15, 2020
New changeset 95b81e2 by Miss Islington (bot) in branch '3.9':
bpo-39587: Enum - use correct mixed-in data type (GH-22263) (GH-22266)
95b81e2