mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528)
(cherry picked from commit b44372e03c)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
eecbeec083
commit
c9480d5ad5
3 changed files with 11 additions and 2 deletions
|
|
@ -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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue