]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-116600: [Enum] fix global Flag repr (GH-116615) (GH-116629)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 12 Mar 2024 00:36:00 +0000 (01:36 +0100)
committerGitHub <noreply@github.com>
Tue, 12 Mar 2024 00:36:00 +0000 (17:36 -0700)
* and fix global flag repr

(cherry picked from commit 06e29a224fac9edeba55422d2e60f2fbb88dddce)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Lib/enum.py
Lib/test/test_enum.py
Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst [new file with mode: 0644]

index 50eca3f03d79f131d3ead410fce07bdb2e783e07..af5613838d12a914519be674c92da82e1b468c61 100644 (file)
@@ -1651,7 +1651,7 @@ def global_flag_repr(self):
     cls_name = self.__class__.__name__
     if self._name_ is None:
         return "%s.%s(%r)" % (module, cls_name, self._value_)
-    if _is_single_bit(self):
+    if _is_single_bit(self._value_):
         return '%s.%s' % (module, self._name_)
     if self._boundary_ is not FlagBoundary.KEEP:
         return '|'.join(['%s.%s' % (module, name) for name in self.name.split('|')])
index 2fea9f983692b50f5b82d12f44e3fe540d915d19..ccba0f91c868eb2d3109abc5070fccdecf0631a0 100644 (file)
@@ -3959,6 +3959,8 @@ class OldTestIntFlag(unittest.TestCase):
                 )
 
     def test_global_enum_str(self):
+        self.assertEqual(repr(NoName.ONE), 'test_enum.ONE')
+        self.assertEqual(repr(NoName(0)), 'test_enum.NoName(0)')
         self.assertEqual(str(NoName.ONE & NoName.TWO), 'NoName(0)')
         self.assertEqual(str(NoName(0)), 'NoName(0)')
 
diff --git a/Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst b/Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst
new file mode 100644 (file)
index 0000000..e9148ba
--- /dev/null
@@ -0,0 +1 @@
+Fix :func:`repr` for global :class:`~enum.Flag` members.