8000 bpo-44342: [Enum] fix data type search (GH-26667) · python/cpython@0f99324 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f99324

Browse files
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) (cherry picked from commit 3a7cccf) Co-authored-by: Ethan Furman <ethan@stoneleaf.us> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
1 parent 8d0b2ca commit 0f99324

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
@@ -823,7 +823,7 @@ def _find_data_type(bases):
823823
data_types.add(candidate or base)
824824
break
825825
else:
826-
candidate = base
826+
candidate = candidate or base
827827
if len(data_types) > 1:
828828
raise TypeError('%r: too many data types: %r' % (class_name, data_types))
829829
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)
0