]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34909: keep searching mixins until base class is found (GH-9737) (GH-9738)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 6 Oct 2018 07:43:20 +0000 (00:43 -0700)
committerEthan Furman <ethan@stoneleaf.us>
Sat, 6 Oct 2018 07:43:20 +0000 (00:43 -0700)
(cherry picked from commit cd45385ffad8910293e5659cfe7ab036e70613b7)

Lib/enum.py
Lib/test/test_enum.py

index 4e8a56818b3c6e2034fbef976b809381b46b2e48..87f36911144af31c9297924c405e39cb1d3b0f3c 100644 (file)
@@ -455,7 +455,7 @@ class EnumMeta(type):
                     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
 
@@ -468,7 +468,6 @@ class EnumMeta(type):
         member_type = _find_data_type(bases) or object
         if first_enum._member_names_:
             raise TypeError("Cannot extend enumerations")
-
         return member_type, first_enum
 
     @staticmethod
@@ -514,7 +513,6 @@ class EnumMeta(type):
             use_args = False
         else:
             use_args = True
-
         return __new__, save_new, use_args
 
 
index 6c147d7ca6e1f47fb7eeae01627023eaab7b1e8e..60eabbe3d487442d45465aa6ac8dc2503141bb18 100644 (file)
@@ -1813,6 +1813,27 @@ class TestEnum(unittest.TestCase):
         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):