bpo-34909: keep searching mixins until base class is found (GH-9737) · python/cpython@cd45385 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -486,7 +486,7 @@ def _find_data_type(bases):
486 486 if base is object:
487 487 continue
488 488 elif '__new__' in base.__dict__:
489 -if issubclass(base, Enum) and not hasattr(base, '__new_member__'):
489 +if issubclass(base, Enum):
490 490 continue
491 491 return base
492 492
@@ -499,7 +499,6 @@ def _find_data_type(bases):
499 499 member_type = _find_data_type(bases) or object
500 500 if first_enum._member_names_:
501 501 raise TypeError("Cannot extend enumerations")
502 -
503 502 return member_type, first_enum
504 503
505 504 @staticmethod
@@ -545,7 +544,6 @@ def _find_new_(classdict, member_type, first_enum):
545 544 use_args = False
546 545 else:
547 546 use_args = True
548 -
549 547 return __new__, save_new, use_args
550 548
551 549
Original file line number Diff line number Diff line change
@@ -1842,6 +1842,27 @@ class ReformedColor(StrMixin, IntEnum, SomeEnum, AnotherEnum):
1842 1842 self.assertEqual(ConfusedColor.RED.social(), "what's up?")
1843 1843 self.assertTrue(issubclass(ReformedColor, int))
1844 1844
1845 +def test_multiple_inherited_mixin(self):
1846 +class StrEnum(str, Enum):
1847 +def __new__(cls, *args, **kwargs):
1848 +for a in args:
1849 +if not isinstance(a, str):
1850 +raise TypeError("Enumeration '%s' (%s) is not"
1851 +" a string" % (a, type(a).__name__))
1852 +return str.__new__(cls, *args, **kwargs)
1853 +@unique
1854 +class Decision1(StrEnum):
1855 +REVERT = "REVERT"
1856 +REVERT_ALL = "REVERT_ALL"
1857 +RETRY = "RETRY"
1858 +class MyEnum(StrEnum):
1859 +pass
1860 +@unique
1861 +class Decision2(MyEnum):
1862 +REVERT = "REVERT"
1863 +REVERT_ALL = "REVERT_ALL"
1864 +RETRY = "RETRY"
1865 +
1845 1866
1846 1867 class TestOrder(unittest.TestCase):
1847 1868