https://github.com/python/cpython/commit/5562a09821499d3b5f40637f448591ff2466a217 commit: 5562a09821499d3b5f40637f448591ff2466a217 branch: 3.11 author: Miss Islington (bot) <[email protected]> committer: ethanfurman <[email protected]> date: 2024-03-11T17:36:15-07:00 summary:
[3.11] gh-116600: [Enum] fix global Flag repr (GH-116615) (#116630) * and fix global flag repr (cherry picked from commit 06e29a224fac9edeba55422d2e60f2fbb88dddce) Co-authored-by: Ethan Furman <[email protected]> Co-authored-by: Kirill Podoprigora <[email protected]> files: A Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst M Lib/enum.py M Lib/test/test_enum.py diff --git a/Lib/enum.py b/Lib/enum.py index 8c705cf392cfab..4862d2488a490b 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -1611,7 +1611,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 e642b84d7216d0..b317409d7508c6 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -3590,6 +3590,8 @@ def test_global_repr_conform1(self): ) 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 00000000000000..e9148ba9290e7b --- /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. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
