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

ethanfurman webhook-mailer at python.org
Mon May 23 13:11:28 EDT 2022


https://github.com/python/cpython/commit/96218f774e2b3c5a4ded5f48b22ec97e02043def
commit: 96218f774e2b3c5a4ded5f48b22ec97e02043def
branch: 3.11
author: Ethan Furman <ethan at stoneleaf.us>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2022-05-23T10:11:18-07:00
summary:

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

(cherry picked from commit 046df59658c9f64a9f0fc909ed62e92c6c4dd668)

Co-authored-by: Ethan Furman <ethan at stoneleaf.us>

files:
M Lib/enum.py
M Lib/test/test_enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index b9811fe9e6787..43cd1bc2b1e31 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -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_
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index f9e09027228b4..c9ed08397d77c 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -189,6 +189,12 @@ class HeadlightsC(IntFlag, boundary=enum.CONFORM):
     FOG_C = auto()
 
 
+ at 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 @@ 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')



More information about the Python-checkins mailing list