mirror of
https://github.com/python/cpython.git
synced 2024-11-23 09:54:58 +08:00
gh-93847: Fix repr of enum of generic aliases (GH-93885)
This commit is contained in:
parent
ab45c1dde0
commit
138db8e48b
@ -1237,7 +1237,7 @@ class Enum(metaclass=EnumType):
|
||||
return None
|
||||
|
||||
def __repr__(self):
|
||||
v_repr = self.__class__._value_repr_ or self._value_.__class__.__repr__
|
||||
v_repr = self.__class__._value_repr_ or repr
|
||||
return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
|
||||
|
||||
def __str__(self):
|
||||
@ -1512,7 +1512,7 @@ class Flag(Enum, boundary=STRICT):
|
||||
|
||||
def __repr__(self):
|
||||
cls_name = self.__class__.__name__
|
||||
v_repr = self.__class__._value_repr_ or self._value_.__class__.__repr__
|
||||
v_repr = self.__class__._value_repr_ or repr
|
||||
if self._name_ is None:
|
||||
return "<%s: %s>" % (cls_name, v_repr(self._value_))
|
||||
else:
|
||||
|
@ -7,6 +7,7 @@ import pydoc
|
||||
import sys
|
||||
import unittest
|
||||
import threading
|
||||
import typing
|
||||
import builtins as bltns
|
||||
from collections import OrderedDict
|
||||
from datetime import date
|
||||
@ -980,6 +981,15 @@ class TestSpecial(unittest.TestCase):
|
||||
spam = SpamEnumNotInner
|
||||
self.assertEqual(SpamEnum.spam.value, SpamEnumNotInner)
|
||||
|
||||
def test_enum_of_generic_aliases(self):
|
||||
class E(Enum):
|
||||
a = typing.List[int]
|
||||
b = list[int]
|
||||
self.assertEqual(E.a.value, typing.List[int])
|
||||
self.assertEqual(E.b.value, list[int])
|
||||
self.assertEqual(repr(E.a), '<E.a: typing.List[int]>')
|
||||
self.assertEqual(repr(E.b), '<E.b: list[int]>')
|
||||
|
||||
@unittest.skipIf(
|
||||
python_version >= (3, 13),
|
||||
'inner classes are not members',
|
||||
|
@ -0,0 +1 @@
|
||||
Fix repr of enum of generic aliases.
|
Loading…
Reference in New Issue
Block a user