[Python-checkins] bpo-34909: keep searching mixins until base class is found (GH-9737)

Ethan Furman webhook-mailer at python.org
Sat Oct 6 02:29:39 EDT 2018


https://github.com/python/cpython/commit/cd45385ffad8910293e5659cfe7ab036e70613b7
commit: cd45385ffad8910293e5659cfe7ab036e70613b7
branch: master
author: Ethan Furman <ethan at stoneleaf.us>
committer: GitHub <noreply at github.com>
date: 2018-10-05T23:29:36-07:00
summary:

bpo-34909: keep searching mixins until base class is found (GH-9737)

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

diff --git a/Lib/enum.py b/Lib/enum.py
index 0ccb30d428e4..fec1aed9b25c 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -486,7 +486,7 @@ def _find_data_type(bases):
                     if base is object:
                         continue
                     elif '__new__' in base.__dict__:
-                        if issubclass(base, Enum) and not hasattr(base, '__new_member__'):
+                        if issubclass(base, Enum):
                             continue
                         return base
 
@@ -499,7 +499,6 @@ def _find_data_type(bases):
         member_type = _find_data_type(bases) or object
         if first_enum._member_names_:
             raise TypeError("Cannot extend enumerations")
-
         return member_type, first_enum
 
     @staticmethod
@@ -545,7 +544,6 @@ def _find_new_(classdict, member_type, first_enum):
             use_args = False
         else:
             use_args = True
-
         return __new__, save_new, use_args
 
 
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index aadc11fcc49c..216f7d5c2830 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1842,6 +1842,27 @@ class ReformedColor(StrMixin, IntEnum, SomeEnum, AnotherEnum):
         self.assertEqual(ConfusedColor.RED.social(), "what's up?")
         self.assertTrue(issubclass(ReformedColor, int))
 
+    def test_multiple_inherited_mixin(self):
+        class StrEnum(str, Enum):
+            def __new__(cls, *args, **kwargs):
+                for a in args:
+                    if not isinstance(a, str):
+                        raise TypeError("Enumeration '%s' (%s) is not"
+                                        " a string" % (a, type(a).__name__))
+                return str.__new__(cls, *args, **kwargs)
+        @unique
+        class Decision1(StrEnum):
+            REVERT = "REVERT"
+            REVERT_ALL = "REVERT_ALL"
+            RETRY = "RETRY"
+        class MyEnum(StrEnum):
+            pass
+        @unique
+        class Decision2(MyEnum):
+            REVERT = "REVERT"
+            REVERT_ALL = "REVERT_ALL"
+            RETRY = "RETRY"
+
 
 class TestOrder(unittest.TestCase):
 



More information about the Python-checkins mailing list