mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-39587: Enum - use correct mixed-in data type (GH-22263) (GH-22266)
(cherry picked from commit bff01f3a3a
)
This commit is contained in:
parent
49917d576a
commit
95b81e2f8c
3 changed files with 56 additions and 1 deletions
13
Lib/enum.py
13
Lib/enum.py
|
@ -481,14 +481,25 @@ class EnumMeta(type):
|
|||
return object, Enum
|
||||
|
||||
def _find_data_type(bases):
|
||||
data_types = []
|
||||
for chain in bases:
|
||||
candidate = None
|
||||
for base in chain.__mro__:
|
||||
if base is object:
|
||||
continue
|
||||
elif '__new__' in base.__dict__:
|
||||
if issubclass(base, Enum):
|
||||
continue
|
||||
return base
|
||||
data_types.append(candidate or base)
|
||||
break
|
||||
elif not issubclass(base, Enum):
|
||||
candidate = base
|
||||
if len(data_types) > 1:
|
||||
raise TypeError('too many data types: %r' % data_types)
|
||||
elif data_types:
|
||||
return data_types[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
# ensure final parent class is an Enum derivative, find any concrete
|
||||
# data type, and check that Enum has no members
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue