Skip to content

Commit

Permalink
pythongh-96865: [Enum] fix Flag to use CONFORM boundary (pythonGH-97528)
Browse files Browse the repository at this point in the history
(cherry picked from commit b44372e)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
  • Loading branch information
ethanfurman authored and miss-islington committed Oct 5, 2022
1 parent eecbeec commit b7b95ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ class FlagBoundary(StrEnum):
STRICT, CONFORM, EJECT, KEEP = FlagBoundary


class Flag(Enum, boundary=STRICT):
class Flag(Enum, boundary=CONFORM):
"""
Support for flags
"""
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2878,7 +2878,7 @@ def test_bool(self):
self.assertEqual(bool(f.value), bool(f))

def test_boundary(self):
self.assertIs(enum.Flag._boundary_, STRICT)
self.assertIs(enum.Flag._boundary_, CONFORM)
class Iron(Flag, boundary=STRICT):
ONE = 1
TWO = 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fix Flag to use boundary CONFORM

This restores previous Flag behavior of allowing flags with non-sequential values to be combined; e.g.

class Skip(Flag):
TWO = 2
EIGHT = 8

Skip.TWO | Skip.EIGHT -> <Skip.TWO|EIGHT: 10>

0 comments on commit b7b95ba

Please sign in to comment.