Skip to content

Commit 70cfe56

Browse files
authored
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.
1 parent 711eda7 commit 70cfe56

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Lib/enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ def __invert__(self):
15721572
__rxor__ = __xor__
15731573

15741574

1575-
class IntFlag(int, ReprEnum, Flag, boundary=EJECT):
1575+
class IntFlag(int, ReprEnum, Flag, boundary=KEEP):
15761576
"""
15771577
Support for integer-based Flags
15781578
"""

Lib/test/test_enum.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -3353,7 +3353,10 @@ def test_invert(self):
33533353
self.assertIs((Open.WO|Open.CE) & ~Open.WO, Open.CE)
33543354

33553355
def test_boundary(self):
3356-
self.assertIs(enum.IntFlag._boundary_, EJECT)
3356+
self.assertIs(enum.IntFlag._boundary_, KEEP)
3357+
class Simple(IntFlag, boundary=KEEP):
3358+
SINGLE = 1
3359+
#
33573360
class Iron(IntFlag, boundary=STRICT):
33583361
ONE = 1
33593362
TWO = 2
@@ -3372,7 +3375,6 @@ class Space(IntFlag, boundary=EJECT):
33723375
EIGHT = 8
33733376
self.assertIs(Space._boundary_, EJECT)
33743377
#
3375-
#
33763378
class Bizarre(IntFlag, boundary=KEEP):
33773379
b = 3
33783380
c = 4
@@ -3389,6 +3391,12 @@ class Bizarre(IntFlag, boundary=KEEP):
33893391
self.assertEqual(list(Bizarre), [Bizarre.c])
33903392
self.assertIs(Bizarre(3), Bizarre.b)
33913393
self.assertIs(Bizarre(6), Bizarre.d)
3394+
#
3395+
simple = Simple.SINGLE | Iron.TWO
3396+
self.assertEqual(simple, 3)
3397+
self.assertIsInstance(simple, Simple)
3398+
self.assertEqual(repr(simple), '<Simple.SINGLE|<Iron.TWO: 2>: 3>')
3399+
self.assertEqual(str(simple), '3')
33923400

33933401
def test_iter(self):
33943402
Color = self.Color

0 commit comments

Comments
 (0)