diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2021-06-10 20:30:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-10 20:30:41 (GMT) |
commit | 8a4f0850d75747af8c96ca0e7eef1f5c1abfba25 (patch) | |
tree | fde4b0f4a03765b96b3af92818fad1fe00d12b39 /Lib/enum.py | |
parent | 42d5a4fc3b35e45cdd237d56a04e98894d0a31f5 (diff) | |
download | cpython-8a4f0850d75747af8c96ca0e7eef1f5c1abfba25.zip cpython-8a4f0850d75747af8c96ca0e7eef1f5c1abfba25.tar.gz cpython-8a4f0850d75747af8c96ca0e7eef1f5c1abfba25.tar.bz2 |
bpo-44356: [Enum] allow multiple data-type mixins if they are all the same (GH-26649)
This enables, for example, two base Enums to both inherit from `str`, and then both be mixed into the same final Enum:
class Str1Enum(str, Enum):
# some behavior here
class Str2Enum(str, Enum):
# some more behavior here
class FinalStrEnum(Str1Enum, Str2Enum):
# this now works
Diffstat (limited to 'Lib/enum.py')
-rw-r--r-- | Lib/enum.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index f74cc8c..54633d8 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -819,7 +819,7 @@ class EnumType(type): return object, Enum def _find_data_type(bases): - data_types = [] + data_types = set() for chain in bases: candidate = None for base in chain.__mro__: @@ -827,19 +827,19 @@ class EnumType(type): continue elif issubclass(base, Enum): if base._member_type_ is not object: - data_types.append(base._member_type_) + data_types.add(base._member_type_) break elif '__new__' in base.__dict__: if issubclass(base, Enum): continue - data_types.append(candidate or base) + data_types.add(candidate or base) break else: candidate = base if len(data_types) > 1: raise TypeError('%r: too many data types: %r' % (class_name, data_types)) elif data_types: - return data_types[0] + return data_types.pop() else: return None |