Skip to content

Commit 96218f7

Browse files
authored
[3.11] gh-93100: [Enum] fix missing variable in global_str (GH-93107) (GH-93134)
(cherry picked from commit 046df59) Co-authored-by: Ethan Furman <[email protected]>
1 parent a509d26 commit 96218f7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Lib/enum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ def global_str(self):
16431643
use enum_name instead of class.enum_name
16441644
"""
16451645
if self._name_ is None:
1646+
cls_name = self.__class__.__name__
16461647
return "%s(%r)" % (cls_name, self._value_)
16471648
else:
16481649
return self._name_

Lib/test/test_enum.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ class HeadlightsC(IntFlag, boundary=enum.CONFORM):
189189
FOG_C = auto()
190190

191191

192+
@enum.global_enum
193+
class NoName(Flag):
194+
ONE = 1
195+
TWO = 2
196+
197+
192198
# tests
193199

194200
class _EnumTests:
@@ -614,6 +620,7 @@ class _PlainOutputTests:
614620
def test_str(self):
615621
TE = self.MainEnum
616622
if self.is_flag:
623+
self.assertEqual(str(TE(0)), "MainEnum(0)")
617624
self.assertEqual(str(TE.dupe), "MainEnum.dupe")
618625
self.assertEqual(str(self.dupe2), "MainEnum.first|third")
619626
else:
@@ -3238,6 +3245,10 @@ def test_global_repr_conform1(self):
32383245
'%(m)s.OFF_C' % {'m': SHORT_MODULE},
32393246
)
32403247

3248+
def test_global_enum_str(self):
3249+
self.assertEqual(str(NoName.ONE & NoName.TWO), 'NoName(0)')
3250+
self.assertEqual(str(NoName(0)), 'NoName(0)')
3251+
32413252
def test_format(self):
32423253
Perm = self.Perm
32433254
self.assertEqual(format(Perm.R, ''), '4')

0 commit comments

Comments
 (0)