summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2022-05-27 22:14:28 (GMT)
committerGitHub <noreply@github.com>2022-05-27 22:14:28 (GMT)
commit70cfe56cafb2b549983f63d5d1a54654fe63c15c (patch)
treef1be9efa8ae89b95c27236a0ea6ffe63afd4ce48 /Lib
parent711eda7dec1f62ecb2a87b274b5f6bfc2b6fbef4 (diff)
downloadcpython-70cfe56cafb2b549983f63d5d1a54654fe63c15c.zip
cpython-70cfe56cafb2b549983f63d5d1a54654fe63c15c.tar.gz
cpython-70cfe56cafb2b549983f63d5d1a54654fe63c15c.tar.bz2
gh-93250: [Enum] Change IntEnum boundary to KEEP for backwards compatibility (GH-93302)
In previous versions of Python if an IntEnum member was combined with another integer type value using a bit-wise operation, the resulting value would still be the IntEnum type. This change restores that behavior.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/enum.py2
-rw-r--r--Lib/test/test_enum.py12
2 files changed, 11 insertions, 3 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 0b97d3d..4261b11 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -1572,7 +1572,7 @@ class Flag(Enum, boundary=STRICT):
__rxor__ = __xor__
-class IntFlag(int, ReprEnum, Flag, boundary=EJECT):
+class IntFlag(int, ReprEnum, Flag, boundary=KEEP):
"""
Support for integer-based Flags
"""
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 44a3912..25b3e2d 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -3353,7 +3353,10 @@ class OldTestIntFlag(unittest.TestCase):
self.assertIs((Open.WO|Open.CE) & ~Open.WO, Open.CE)
def test_boundary(self):
- self.assertIs(enum.IntFlag._boundary_, EJECT)
+ self.assertIs(enum.IntFlag._boundary_, KEEP)
+ class Simple(IntFlag, boundary=KEEP):
+ SINGLE = 1
+ #
class Iron(IntFlag, boundary=STRICT):
ONE = 1
TWO = 2
@@ -3372,7 +3375,6 @@ class OldTestIntFlag(unittest.TestCase):
EIGHT = 8
self.assertIs(Space._boundary_, EJECT)
#
- #
class Bizarre(IntFlag, boundary=KEEP):
b = 3
c = 4
@@ -3389,6 +3391,12 @@ class OldTestIntFlag(unittest.TestCase):
self.assertEqual(list(Bizarre), [Bizarre.c])
self.assertIs(Bizarre(3), Bizarre.b)
self.assertIs(Bizarre(6), Bizarre.d)
+ #
+ simple = Simple.SINGLE | Iron.TWO
+ self.assertEqual(simple, 3)
+ self.assertIsInstance(simple, Simple)
+ self.assertEqual(repr(simple), '<Simple.SINGLE|<Iron.TWO: 2>: 3>')
+ self.assertEqual(str(simple), '3')
def test_iter(self):
Color = self.Color