Skip to content

Commit

Permalink
pythongh-116600: [Enum] fix global Flag repr (pythonGH-116615)
Browse files Browse the repository at this point in the history
* and fix global flag repr

* Update Misc/NEWS.d/next/Library/2024-03-11-12-11-10.gh-issue-116600.FcNBy_.rst

(cherry picked from commit 06e29a2)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
  • Loading branch information
2 people authored and miss-islington committed Mar 11, 2024
1 parent 830fbe9 commit 9f4e756
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/enum.py
Expand Up @@ -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('|')])
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_enum.py
Expand Up @@ -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)')

Expand Down
@@ -0,0 +1 @@
Fix :func:`repr` for global :class:`~enum.Flag` members.

0 comments on commit 9f4e756

Please sign in to comment.