[Python-checkins] bpo-44342: [Enum] fix data type search (GH-26667)

ethanfurman webhook-mailer at python.org
Tue Jun 15 17:07:58 EDT 2021


https://github.com/python/cpython/commit/0f99324f61d5a2edd8729be5eed6f172c892af24
commit: 0f99324f61d5a2edd8729be5eed6f172c892af24
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2021-06-15T14:07:37-07:00
summary:

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 3a7cccfd6cd3693e1a2ab65ee05d7f45f8501dfa)

Co-authored-by: Ethan Furman <ethan at stoneleaf.us>

Co-authored-by: Ethan Furman <ethan at stoneleaf.us>

files:
M Lib/enum.py
M Lib/test/test_enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index 9f9c89e8a4b26..49c46ea86dbac 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -823,7 +823,7 @@ def _find_data_type(bases):
                         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:
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index ceb0da8c77ba3..956b8347b1e1c 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -658,6 +658,14 @@ class MyEnum(HexInt, enum.Enum):
             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'):



More information about the Python-checkins mailing list