mirror of https://github.com/python/cpython
[3.11] gh-93100: [Enum] fix missing variable in global_str (GH-93107) (GH-93134)
(cherry picked from commit 046df59658
)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
a509d2674a
commit
96218f774e
|
@ -1643,6 +1643,7 @@ def global_str(self):
|
|||
use enum_name instead of class.enum_name
|
||||
"""
|
||||
if self._name_ is None:
|
||||
cls_name = self.__class__.__name__
|
||||
return "%s(%r)" % (cls_name, self._value_)
|
||||
else:
|
||||
return self._name_
|
||||
|
|
|
@ -189,6 +189,12 @@ class HeadlightsC(IntFlag, boundary=enum.CONFORM):
|
|||
FOG_C = auto()
|
||||
|
||||
|
||||
@enum.global_enum
|
||||
class NoName(Flag):
|
||||
ONE = 1
|
||||
TWO = 2
|
||||
|
||||
|
||||
# tests
|
||||
|
||||
class _EnumTests:
|
||||
|
@ -614,6 +620,7 @@ class _PlainOutputTests:
|
|||
def test_str(self):
|
||||
TE = self.MainEnum
|
||||
if self.is_flag:
|
||||
self.assertEqual(str(TE(0)), "MainEnum(0)")
|
||||
self.assertEqual(str(TE.dupe), "MainEnum.dupe")
|
||||
self.assertEqual(str(self.dupe2), "MainEnum.first|third")
|
||||
else:
|
||||
|
@ -3238,6 +3245,10 @@ class OldTestIntFlag(unittest.TestCase):
|
|||
'%(m)s.OFF_C' % {'m': SHORT_MODULE},
|
||||
)
|
||||
|
||||
def test_global_enum_str(self):
|
||||
self.assertEqual(str(NoName.ONE & NoName.TWO), 'NoName(0)')
|
||||
self.assertEqual(str(NoName(0)), 'NoName(0)')
|
||||
|
||||
def test_format(self):
|
||||
Perm = self.Perm
|
||||
self.assertEqual(format(Perm.R, ''), '4')
|
||||
|
|
Loading…
Reference in New Issue