FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.11] gh-102558: [Enum] fix AttributeError during member repr() (GH-102601) by miss-islington · Pull Request #102977 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions Lib/enum.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,8 @@ def _missing_(cls, value):
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_))

Expand Down
9 changes: 8 additions & 1 deletion Lib/test/test_enum.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand Down Expand Up @@ -632,6 +632,13 @@ class MySubEnum(MyEnum):
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)),
Expand Down

Back | FazBrowse Home | New Git URL