]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528)
authorEthan Furman <ethan@stoneleaf.us>
Wed, 5 Oct 2022 22:25:55 +0000 (15:25 -0700)
committerGitHub <noreply@github.com>
Wed, 5 Oct 2022 22:25:55 +0000 (15:25 -0700)
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 c3aafc283719ab5c32e5e41a604771bff047050d..a66c344dbc3db271843cef6f1965c5b72daf8818 100644 (file)
@@ -1269,7 +1269,7 @@ class FlagBoundary(StrEnum):
 STRICT, CONFORM, EJECT, KEEP = FlagBoundary
 
 
-class Flag(Enum, boundary=STRICT):
+class Flag(Enum, boundary=CONFORM):
     """
     Support for flags
     """
index ad421f87d6d07c46e868efe2eef507fbb9234e03..f50017d916f5e32ac95760bf07067c8f1411cb09 100644 (file)
@@ -2927,7 +2927,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>