]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 5 Oct 2022 23:32:16 +0000 (16:32 -0700)
committerGitHub <noreply@github.com>
Wed, 5 Oct 2022 23:32:16 +0000 (16:32 -0700)
(cherry picked from commit b44372e03c5461b6ad3d89763a9eb6cb82df07a4)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Lib/enum.py
Lib/test/test_enum.py
Misc/NEWS.d/next/Library/2022-09-24-18-56-23.gh-issue-96865.o9WUkW.rst [new file with mode: 0644]

index dffb673f44f949fff0d93f1e8852cebfcc755567..ae97334e220bf0ec4ae482a032f9e9e54efa6764 100644 (file)
@@ -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
     """
index 3b1c77d688eca1dfed34b3f19303f59930886c83..d2cfc7f7cd4b91c5b6b0262d57b211e1934b8ca3 100644 (file)
@@ -2878,7 +2878,7 @@ class OldTestFlag(unittest.TestCase):
             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
diff --git a/Misc/NEWS.d/next/Library/2022-09-24-18-56-23.gh-issue-96865.o9WUkW.rst b/Misc/NEWS.d/next/Library/2022-09-24-18-56-23.gh-issue-96865.o9WUkW.rst
new file mode 100644 (file)
index 0000000..b054fde
--- /dev/null
@@ -0,0 +1,9 @@
+fix Flag to use boundary CONFORM\r
+\r
+This restores previous Flag behavior of allowing flags with non-sequential values to be combined; e.g.\r
+\r
+    class Skip(Flag):\r
+        TWO = 2\r
+        EIGHT = 8\r
+\r
+    Skip.TWO | Skip.EIGHT -> <Skip.TWO|EIGHT: 10>