mirror of https://github.com/python/cpython
gh-102558: [Enum] fix AttributeError during member repr() (GH-102601)
This commit is contained in:
parent
16f6165b71
commit
bd063756b3
|
@ -1186,6 +1186,8 @@ 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_))
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import typing
|
|||
import builtins as bltns
|
||||
from collections import OrderedDict
|
||||
from datetime import date
|
||||
from enum import Enum, IntEnum, StrEnum, EnumType, Flag, IntFlag, unique, auto
|
||||
from enum import Enum, EnumMeta, IntEnum, StrEnum, EnumType, Flag, IntFlag, unique, auto
|
||||
from enum import STRICT, CONFORM, EJECT, KEEP, _simple_enum, _test_simple_enum
|
||||
from enum import verify, UNIQUE, CONTINUOUS, NAMED_FLAGS, ReprEnum
|
||||
from enum import member, nonmember, _iter_bits_lsb
|
||||
|
@ -644,6 +644,13 @@ class _EnumTests:
|
|||
theother = auto()
|
||||
self.assertEqual(repr(MySubEnum.that), "My name is that.")
|
||||
|
||||
def test_multiple_superclasses_repr(self):
|
||||
class _EnumSuperClass(metaclass=EnumMeta):
|
||||
pass
|
||||
class E(_EnumSuperClass, Enum):
|
||||
A = 1
|
||||
self.assertEqual(repr(E.A), "<E.A: 1>")
|
||||
|
||||
def test_reversed_iteration_order(self):
|
||||
self.assertEqual(
|
||||
list(reversed(self.MainEnum)),
|
||||
|
|
Loading…
Reference in New Issue