summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2023-03-27 23:26:16 (GMT)
committerGitHub <noreply@github.com>2023-03-27 23:26:16 (GMT)
commitf4ed2c6ae5915329e49b9f94033ef182400e29fa (patch)
tree70e3afc7594277ba666bf9bcb873d7009eba11ff /Lib
parentb838d80085b0162cc2ae7b4db5d2a9d9c6a28366 (diff)
downloadcpython-f4ed2c6ae5915329e49b9f94033ef182400e29fa.zip
cpython-f4ed2c6ae5915329e49b9f94033ef182400e29fa.tar.gz
cpython-f4ed2c6ae5915329e49b9f94033ef182400e29fa.tar.bz2
gh-102558: [Enum] better handling of non-Enum EnumType classes (GH-103060)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/enum.py12
-rw-r--r--Lib/test/test_enum.py1
2 files changed, 5 insertions, 8 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 2624a08..8c77117 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -928,7 +928,7 @@ class EnumType(type):
def _check_for_existing_members_(mcls, class_name, bases):
for chain in bases:
for base in chain.__mro__:
- if issubclass(base, Enum) and base._member_names_:
+ if isinstance(base, EnumType) and base._member_names_:
raise TypeError(
"<enum %r> cannot extend %r"
% (class_name, base)
@@ -947,7 +947,7 @@ class EnumType(type):
# ensure final parent class is an Enum derivative, find any concrete
# data type, and check that Enum has no members
first_enum = bases[-1]
- if not issubclass(first_enum, Enum):
+ if not isinstance(first_enum, EnumType):
raise TypeError("new enumerations should be created as "
"`EnumName([mixin_type, ...] [data_type,] enum_type)`")
member_type = mcls._find_data_type_(class_name, bases) or object
@@ -959,7 +959,7 @@ class EnumType(type):
for base in chain.__mro__:
if base is object:
continue
- elif issubclass(base, Enum):
+ elif isinstance(base, EnumType):
# if we hit an Enum, use it's _value_repr_
return base._value_repr_
elif '__repr__' in base.__dict__:
@@ -985,12 +985,12 @@ class EnumType(type):
base_chain.add(base)
if base is object:
continue
- elif issubclass(base, Enum):
+ elif isinstance(base, EnumType):
if base._member_type_ is not object:
data_types.add(base._member_type_)
break
elif '__new__' in base.__dict__ or '__init__' in base.__dict__:
- if issubclass(base, Enum):
+ if isinstance(base, EnumType):
continue
data_types.add(candidate or base)
break
@@ -1191,8 +1191,6 @@ class Enum(metaclass=EnumType):
return None
def __repr__(self):
- if not isinstance(self, Enum):
- return repr(self)
v_repr = self.__class__._value_repr_ or repr
return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 58c80e7..bea1954 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1386,7 +1386,6 @@ class TestSpecial(unittest.TestCase):
class Huh(MyStr, MyInt, Enum):
One = 1
-
def test_pickle_enum(self):
if isinstance(Stooges, Exception):
raise Stooges