mirror of
https://github.com/python/cpython.git
synced 2025-09-28 03:13:48 +00:00
gh93107: [Enum] fix missing variable in global_str (GH-93107)
This commit is contained in:
parent
b2694ab469
commit
046df59658
2 changed files with 12 additions and 0 deletions
|
@ -1640,6 +1640,7 @@ def global_str(self):
|
||||||
use enum_name instead of class.enum_name
|
use enum_name instead of class.enum_name
|
||||||
"""
|
"""
|
||||||
if self._name_ is None:
|
if self._name_ is None:
|
||||||
|
cls_name = self.__class__.__name__
|
||||||
return "%s(%r)" % (cls_name, self._value_)
|
return "%s(%r)" % (cls_name, self._value_)
|
||||||
else:
|
else:
|
||||||
return self._name_
|
return self._name_
|
||||||
|
|
|
@ -189,6 +189,12 @@ class HeadlightsC(IntFlag, boundary=enum.CONFORM):
|
||||||
FOG_C = auto()
|
FOG_C = auto()
|
||||||
|
|
||||||
|
|
||||||
|
@enum.global_enum
|
||||||
|
class NoName(Flag):
|
||||||
|
ONE = 1
|
||||||
|
TWO = 2
|
||||||
|
|
||||||
|
|
||||||
# tests
|
# tests
|
||||||
|
|
||||||
class _EnumTests:
|
class _EnumTests:
|
||||||
|
@ -616,6 +622,7 @@ class _PlainOutputTests:
|
||||||
def test_str(self):
|
def test_str(self):
|
||||||
TE = self.MainEnum
|
TE = self.MainEnum
|
||||||
if self.is_flag:
|
if self.is_flag:
|
||||||
|
self.assertEqual(str(TE(0)), "MainEnum(0)")
|
||||||
self.assertEqual(str(TE.dupe), "MainEnum.dupe")
|
self.assertEqual(str(TE.dupe), "MainEnum.dupe")
|
||||||
self.assertEqual(str(self.dupe2), "MainEnum.first|third")
|
self.assertEqual(str(self.dupe2), "MainEnum.first|third")
|
||||||
else:
|
else:
|
||||||
|
@ -3242,6 +3249,10 @@ class OldTestIntFlag(unittest.TestCase):
|
||||||
'%(m)s.OFF_C' % {'m': SHORT_MODULE},
|
'%(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):
|
def test_format(self):
|
||||||
Perm = self.Perm
|
Perm = self.Perm
|
||||||
self.assertEqual(format(Perm.R, ''), '4')
|
self.assertEqual(format(Perm.R, ''), '4')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue