Skip to content

Commit 3a7cccf

Browse files
authored
bpo-44342: [Enum] fix data type search (GH-26667)
In an inheritance chain of int -> my_int -> final_int the data type is now final_int (not my_int)
1 parent e26014f commit 3a7cccf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Lib/enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ def _find_data_type(bases):
818818
data_types.add(candidate or base)
819819
break
820820
else:
821-
candidate = base
821+
candidate = candidate or base
822822
if len(data_types) > 1:
823823
raise TypeError('%r: too many data types: %r' % (class_name, data_types))
824824
elif data_types:

Lib/test/test_enum.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,14 @@ class MyEnum(HexInt, enum.Enum):
658658
def __repr__(self):
659659
return '<%s.%s: %r>' % (self.__class__.__name__, self._name_, self._value_)
660660
self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>')
661+
#
662+
class SillyInt(HexInt):
663+
pass
664+
class MyOtherEnum(SillyInt, enum.Enum):
665+
D = 4
666+
E = 5
667+
F = 6
668+
self.assertIs(MyOtherEnum._member_type_, SillyInt)
661669

662670
def test_too_many_data_types(self):
663671
with self.assertRaisesRegex(TypeError, 'too many data types'):

0 commit comments

Comments
 (0)