diff options
author | 2024-03-11 15:41:53 -0700 | |
---|---|---|
committer | 2024-03-11 15:41:53 -0700 | |
commit | 06e29a224fac9edeba55422d2e60f2fbb88dddce (patch) | |
tree | 1baab91db0d79d0a1d1ddac2c8d353fca77918c1 | |
parent | gh-116563: Update tutorial error example (#116569) (diff) | |
download | cpython-06e29a224fac9edeba55422d2e60f2fbb88dddce.tar.gz cpython-06e29a224fac9edeba55422d2e60f2fbb88dddce.tar.bz2 cpython-06e29a224fac9edeba55422d2e60f2fbb88dddce.zip |
gh-116600: [Enum] fix global Flag repr (GH-116615)
* and fix global flag repr
* Update Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
-rw-r--r-- | Lib/enum.py | 2 | ||||
-rw-r--r-- | Lib/test/test_enum.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst | 1 |
3 files changed, 4 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index bcf7aae949f..5c5e711f9b0 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -1680,7 +1680,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('|')]) diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index a83aca406cb..6418d243db6 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -4063,6 +4063,8 @@ class OldTestIntFlag(unittest.TestCase): @reraise_if_not_enum(NoName) 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 index 00000000000..e9148ba9290 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst @@ -0,0 +1 @@ +Fix :func:`repr` for global :class:`~enum.Flag` members. |