[Python-checkins] gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528)

miss-islington webhook-mailer at python.org
Wed Oct 5 19:32:22 EDT 2022


https://github.com/python/cpython/commit/c9480d5ad59b052ad3d3422fcf0ac8dd5fed7f6d
commit: c9480d5ad59b052ad3d3422fcf0ac8dd5fed7f6d
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-10-05T16:32:16-07:00
summary:

gh-96865: [Enum] fix Flag to use CONFORM boundary (GH-97528)

(cherry picked from commit b44372e03c5461b6ad3d89763a9eb6cb82df07a4)

Co-authored-by: Ethan Furman <ethan at stoneleaf.us>

files:
A Misc/NEWS.d/next/Library/2022-09-24-18-56-23.gh-issue-96865.o9WUkW.rst
M Lib/enum.py
M Lib/test/test_enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index dffb673f44f9..ae97334e220b 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -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
     """
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 3b1c77d688ec..d2cfc7f7cd4b 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -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
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
index 000000000000..b054fdeee078
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-09-24-18-56-23.gh-issue-96865.o9WUkW.rst
@@ -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>



More information about the Python-checkins mailing list