summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-05 11:39:59 (GMT)
committerGitHub <noreply@github.com>2023-07-05 11:39:59 (GMT)
commit74d84cf84d18e8cf69ffef0d7955f80fbc47220a (patch)
tree184ffe0cda35a537005535bc119c730c6efa216e /Lib/test
parentda672b2d245fb439f4ff895636bf284e352fa631 (diff)
downloadcpython-74d84cf84d18e8cf69ffef0d7955f80fbc47220a.zip
cpython-74d84cf84d18e8cf69ffef0d7955f80fbc47220a.tar.gz
cpython-74d84cf84d18e8cf69ffef0d7955f80fbc47220a.tar.bz2
[3.12] gh-105497: [Enum] Fix Flag inversion when alias/mask members exist. (GH-105542) (#105572)
gh-105497: [Enum] Fix Flag inversion when alias/mask members exist. (GH-105542) When inverting a Flag member (or boundary STRICT), only consider other canonical flags; when inverting an IntFlag member (or boundary KEEP), also consider aliases. (cherry picked from commit 59f009e5898a006cdc8f5249be589de6edfe5cd0) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_enum.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index b4ac3ab..291213a 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -3045,6 +3045,33 @@ class OldTestFlag(unittest.TestCase):
WHITE = RED|GREEN|BLUE
BLANCO = RED|GREEN|BLUE
+ class Complete(Flag):
+ A = 0x01
+ B = 0x02
+
+ class Partial(Flag):
+ A = 0x01
+ B = 0x02
+ MASK = 0xff
+
+ class CompleteInt(IntFlag):
+ A = 0x01
+ B = 0x02
+
+ class PartialInt(IntFlag):
+ A = 0x01
+ B = 0x02
+ MASK = 0xff
+
+ class CompleteIntStrict(IntFlag, boundary=STRICT):
+ A = 0x01
+ B = 0x02
+
+ class PartialIntStrict(IntFlag, boundary=STRICT):
+ A = 0x01
+ B = 0x02
+ MASK = 0xff
+
def test_or(self):
Perm = self.Perm
for i in Perm:
@@ -3103,6 +3130,18 @@ class OldTestFlag(unittest.TestCase):
Open = self.Open
self.assertIs(Open.WO & ~Open.WO, Open.RO)
self.assertIs((Open.WO|Open.CE) & ~Open.WO, Open.CE)
+ Complete = self.Complete
+ self.assertIs(~Complete.A, Complete.B)
+ Partial = self.Partial
+ self.assertIs(~Partial.A, Partial.B)
+ CompleteInt = self.CompleteInt
+ self.assertIs(~CompleteInt.A, CompleteInt.B)
+ PartialInt = self.PartialInt
+ self.assertIs(~PartialInt.A, PartialInt(254))
+ CompleteIntStrict = self.CompleteIntStrict
+ self.assertIs(~CompleteIntStrict.A, CompleteIntStrict.B)
+ PartialIntStrict = self.PartialIntStrict
+ self.assertIs(~PartialIntStrict.A, PartialIntStrict.B)
def test_bool(self):
Perm = self.Perm