Skip to content

Commit b7b95ba

Browse files
ethanfurmanmiss-islington
authored andcommitted
pythongh-96865: [Enum] fix Flag to use CONFORM boundary (pythonGH-97528)
(cherry picked from commit b44372e) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
1 parent eecbeec commit b7b95ba

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Lib/enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ class FlagBoundary(StrEnum):
12921292
STRICT, CONFORM, EJECT, KEEP = FlagBoundary
12931293

12941294

1295-
class Flag(Enum, boundary=STRICT):
1295+
class Flag(Enum, boundary=CONFORM):
12961296
"""
12971297
Support for flags
12981298
"""

Lib/test/test_enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2878,7 +2878,7 @@ def test_bool(self):
28782878
self.assertEqual(bool(f.value), bool(f))
28792879

28802880
def test_boundary(self):
2881-
self.assertIs(enum.Flag._boundary_, STRICT)
2881+
self.assertIs(enum.Flag._boundary_, CONFORM)
28822882
class Iron(Flag, boundary=STRICT):
28832883
ONE = 1
28842884
TWO = 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fix Flag to use boundary CONFORM
2+
3+
This restores previous Flag behavior of allowing flags with non-sequential values to be combined; e.g.
4+
5+
class Skip(Flag):
6+
TWO = 2
7+
EIGHT = 8
8+
9+
Skip.TWO | Skip.EIGHT -> <Skip.TWO|EIGHT: 10>

0 commit comments

Comments
 (0)