summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-09-15 23:23:57 (GMT)
committerGitHub <noreply@github.com>2020-09-15 23:23:57 (GMT)
commit8f8ebcca95d3b6ed0a522a9736ab53d6d4f0208c (patch)
treecc6fdcb1d32d906e0de29dc4c8e3664b8e59a81c /Lib/enum.py
parent5fdc1425974c794966da1d91d54b4717d1ceeeff (diff)
downloadcpython-8f8ebcca95d3b6ed0a522a9736ab53d6d4f0208c.zip
cpython-8f8ebcca95d3b6ed0a522a9736ab53d6d4f0208c.tar.gz
cpython-8f8ebcca95d3b6ed0a522a9736ab53d6d4f0208c.tar.bz2
bpo-39587: Enum - use correct mixed-in data type (GH-22263)
(cherry picked from commit bff01f3a3aac0c15fe8fbe8b2f561f7927d117a1) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 16033b1..dfde750 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -487,14 +487,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