mirror of https://github.com/python/cpython.git
gh-102558: [Enum] fix AttributeError during member repr() (GH-102601)
(cherry picked from commit bd063756b3
)
Co-authored-by: Dong-hee Na <donghee.na@python.org>
This commit is contained in:
parent
60b2b58f87
commit
8132aefa0f
|
@ -1187,6 +1187,8 @@ def _missing_(cls, value):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
if not isinstance(self, Enum):
|
||||||
|
return repr(self)
|
||||||
v_repr = self.__class__._value_repr_ or repr
|
v_repr = self.__class__._value_repr_ or repr
|
||||||
return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
|
return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
import builtins as bltns
|
import builtins as bltns
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import date
|
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 STRICT, CONFORM, EJECT, KEEP, _simple_enum, _test_simple_enum
|
||||||
from enum import verify, UNIQUE, CONTINUOUS, NAMED_FLAGS, ReprEnum
|
from enum import verify, UNIQUE, CONTINUOUS, NAMED_FLAGS, ReprEnum
|
||||||
from enum import member, nonmember, _iter_bits_lsb
|
from enum import member, nonmember, _iter_bits_lsb
|
||||||
|
@ -632,6 +632,13 @@ class MySubEnum(MyEnum):
|
||||||
theother = auto()
|
theother = auto()
|
||||||
self.assertEqual(repr(MySubEnum.that), "My name is that.")
|
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):
|
def test_reversed_iteration_order(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
list(reversed(self.MainEnum)),
|
list(reversed(self.MainEnum)),
|
||||||
|
|
Loading…
Reference in New Issue