Skip to content

Commit 5247062

Browse files
committed
[3.10] [Enum] improve test, add andrei kulakov to ACKS (GH-26726).
(cherry picked from commit cb2014f) Co-authored-by: Ethan Furman <[email protected]>
1 parent f6cf38c commit 5247062

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Lib/test/test_enum.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,37 @@ class MyEnum(HexInt, enum.Enum):
658658
def __repr__(self):
659659
return '<%s.%s: %r>' % (self.__class__.__name__, self._name_, self._value_)
660660
self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>')
661+
#
662+
class SillyInt(HexInt):
663+
__qualname__ = 'SillyInt'
664+
pass
665+
class MyOtherEnum(SillyInt, enum.Enum):
666+
__qualname__ = 'MyOtherEnum'
667+
D = 4
668+
E = 5
669+
F = 6
670+
self.assertIs(MyOtherEnum._member_type_, SillyInt)
671+
globals()['SillyInt'] = SillyInt
672+
globals()['MyOtherEnum'] = MyOtherEnum
673+
test_pickle_dump_load(self.assertIs, MyOtherEnum.E)
674+
test_pickle_dump_load(self.assertIs, MyOtherEnum)
675+
#
676+
# This did not work in 3.9, but does now with pickling by name
677+
class UnBrokenInt(int):
678+
__qualname__ = 'UnBrokenInt'
679+
def __new__(cls, value):
680+
return int.__new__(cls, value)
681+
class MyUnBrokenEnum(UnBrokenInt, Enum):
682+
__qualname__ = 'MyUnBrokenEnum'
683+
G = 7
684+
H = 8
685+
I = 9
686+
self.assertIs(MyUnBrokenEnum._member_type_, UnBrokenInt)
687+
self.assertIs(MyUnBrokenEnum(7), MyUnBrokenEnum.G)
688+
globals()['UnBrokenInt'] = UnBrokenInt
689+
globals()['MyUnBrokenEnum'] = MyUnBrokenEnum
690+
test_pickle_dump_load(self.assertIs, MyUnBrokenEnum.I)
691+
test_pickle_dump_load(self.assertIs, MyUnBrokenEnum)
661692

662693
def test_too_many_data_types(self):
663694
with self.assertRaisesRegex(TypeError, 'too many data types'):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ Andrew Kuchling
970970
Jakub Kuczys
971971
Dave Kuhlman
972972
Jon Kuhn
973+
Andrei Kulakov
973974
Ilya Kulakov
974975
Upendra Kumar
975976
Toshio Kuratomi

0 commit comments

Comments
 (0)