]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44342: [Enum] fix data type search (GH-26667) 26742/head
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 15 Jun 2021 21:07:37 +0000 (14:07 -0700)
committerGitHub <noreply@github.com>
Tue, 15 Jun 2021 21:07:37 +0000 (14:07 -0700)
In an inheritance chain of

  int -> my_int -> final_int

the data type is now final_int (not my_int)
(cherry picked from commit 3a7cccfd6cd3693e1a2ab65ee05d7f45f8501dfa)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Lib/enum.py
Lib/test/test_enum.py

index 9f9c89e8a4b268af30e0d6292472096dbc40a0cd..49c46ea86dbacfa2b111fbb25c1ab588209a4a63 100644 (file)
@@ -823,7 +823,7 @@ class EnumType(type):
                         data_types.add(candidate or base)
                         break
                     else:
-                        candidate = base
+                        candidate = candidate or base
             if len(data_types) > 1:
                 raise TypeError('%r: too many data types: %r' % (class_name, data_types))
             elif data_types:
index ceb0da8c77ba3c80ae2951656e6878bc7df62dac..956b8347b1e1cb9e40f74ece6e4819cee5e01d43 100644 (file)
@@ -658,6 +658,14 @@ class TestEnum(unittest.TestCase):
             def __repr__(self):
                 return '<%s.%s: %r>' % (self.__class__.__name__, self._name_, self._value_)
         self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>')
+        #
+        class SillyInt(HexInt):
+            pass
+        class MyOtherEnum(SillyInt, enum.Enum):
+            D = 4
+            E = 5
+            F = 6
+        self.assertIs(MyOtherEnum._member_type_, SillyInt)
 
     def test_too_many_data_types(self):
         with self.assertRaisesRegex(TypeError, 'too many data types'):