]> 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)
committerPablo Galindo <pablogsal@gmail.com>
Sat, 22 Oct 2022 19:48:32 +0000 (20:48 +0100)
(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 28b638c28f17763ccba3319e3407f5890ad69c18..ff8f5cc453170ebafacda77159be3ac3c51ffc4f 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 7964d3e474cd27ae55d028e62c6b9e61c9a295f7..8cd1fe1c106c8acb67402ad09377fa4a23e9bb28 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>