mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[Enum] improve test, add andrei kulakov to ACKS (GH-26726)
This commit is contained in:
parent
243fd01047
commit
cb2014f207
2 changed files with 24 additions and 0 deletions
|
@ -660,12 +660,35 @@ class TestEnum(unittest.TestCase):
|
||||||
self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>')
|
self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>')
|
||||||
#
|
#
|
||||||
class SillyInt(HexInt):
|
class SillyInt(HexInt):
|
||||||
|
__qualname__ = 'SillyInt'
|
||||||
pass
|
pass
|
||||||
class MyOtherEnum(SillyInt, enum.Enum):
|
class MyOtherEnum(SillyInt, enum.Enum):
|
||||||
|
__qualname__ = 'MyOtherEnum'
|
||||||
D = 4
|
D = 4
|
||||||
E = 5
|
E = 5
|
||||||
F = 6
|
F = 6
|
||||||
self.assertIs(MyOtherEnum._member_type_, SillyInt)
|
self.assertIs(MyOtherEnum._member_type_, SillyInt)
|
||||||
|
globals()['SillyInt'] = SillyInt
|
||||||
|
globals()['MyOtherEnum'] = MyOtherEnum
|
||||||
|
test_pickle_dump_load(self.assertIs, MyOtherEnum.E)
|
||||||
|
test_pickle_dump_load(self.assertIs, MyOtherEnum)
|
||||||
|
#
|
||||||
|
# This did not work in 3.9, but does now with pickling by name
|
||||||
|
class UnBrokenInt(int):
|
||||||
|
__qualname__ = 'UnBrokenInt'
|
||||||
|
def __new__(cls, value):
|
||||||
|
return int.__new__(cls, value)
|
||||||
|
class MyUnBrokenEnum(UnBrokenInt, Enum):
|
||||||
|
__qualname__ = 'MyUnBrokenEnum'
|
||||||
|
G = 7
|
||||||
|
H = 8
|
||||||
|
I = 9
|
||||||
|
self.assertIs(MyUnBrokenEnum._member_type_, UnBrokenInt)
|
||||||
|
self.assertIs(MyUnBrokenEnum(7), MyUnBrokenEnum.G)
|
||||||
|
globals()['UnBrokenInt'] = UnBrokenInt
|
||||||
|
globals()['MyUnBrokenEnum'] = MyUnBrokenEnum
|
||||||
|
test_pickle_dump_load(self.assertIs, MyUnBrokenEnum.I)
|
||||||
|
test_pickle_dump_load(self.assertIs, MyUnBrokenEnum)
|
||||||
|
|
||||||
def test_too_many_data_types(self):
|
def test_too_many_data_types(self):
|
||||||
with self.assertRaisesRegex(TypeError, 'too many data types'):
|
with self.assertRaisesRegex(TypeError, 'too many data types'):
|
||||||
|
|
|
@ -970,6 +970,7 @@ Andrew Kuchling
|
||||||
Jakub Kuczys
|
Jakub Kuczys
|
||||||
Dave Kuhlman
|
Dave Kuhlman
|
||||||
Jon Kuhn
|
Jon Kuhn
|
||||||
|
Andrei Kulakov
|
||||||
Ilya Kulakov
|
Ilya Kulakov
|
||||||
Upendra Kumar
|
Upendra Kumar
|
||||||
Toshio Kuratomi
|
Toshio Kuratomi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue