Skip to content

Commit

Permalink
[3.11] gh-93100: [Enum] fix missing variable in global_str (GH-93107) (
Browse files Browse the repository at this point in the history
…GH-93134)

(cherry picked from commit 046df59)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
  • Loading branch information
ethanfurman committed May 23, 2022
1 parent a509d26 commit 96218f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib/enum.py
Expand Up @@ -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_
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_enum.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -3238,6 +3245,10 @@ def test_global_repr_conform1(self):
'%(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')
Expand Down

0 comments on commit 96218f7

Please sign in to comment.