Skip to content

[3.11] gh-93100: [Enum] fix missing variable in global_str (GH-93107) #93134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/enum.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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