Skip to content

Commit

Permalink
[3.10] bpo-44342: [Enum] improve test, add andrei kulakov to ACKS (py…
Browse files Browse the repository at this point in the history
…thonGH-26726)

* [3.10] [Enum] improve test, add andrei kulakov to ACKS (pythonGH-26726).
(cherry picked from commit cb2014f)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
  • Loading branch information
ethanfurman committed Jun 16, 2021
1 parent 0f99324 commit 41c2a4a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ Data Types
... NEON = 31
Traceback (most recent call last):
...
ValueError: invalid Flag 'Color': 'WHITE' is missing a named flag for value 8; 'NEON' is missing named flags for values 8, 16
ValueError: invalid Flag 'Color': aliases WHITE and NEON are missing combined values of 0x18 [use enum.show_flag_values(value) for details]

.. note::

Expand Down
2 changes: 1 addition & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ def __call__(self, enumeration):
else:
value = 'combined values of 0x%x' % missing_value
raise ValueError(
'invalid Flag %r: %s %s [use `enum.show_flag_values(value)` for details]'
'invalid Flag %r: %s %s [use enum.show_flag_values(value) for details]'
% (cls_name, alias, value)
)
return enumeration
Expand Down
27 changes: 25 additions & 2 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,35 @@ def __repr__(self):
self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>')
#
class SillyInt(HexInt):
__qualname__ = 'SillyInt'
pass
class MyOtherEnum(SillyInt, enum.Enum):
__qualname__ = 'MyOtherEnum'
D = 4
E = 5
F = 6
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):
with self.assertRaisesRegex(TypeError, 'too many data types'):
Expand Down Expand Up @@ -3591,7 +3614,7 @@ class Bizarre(Flag):
self.assertEqual(Bizarre.d.value, 6)
with self.assertRaisesRegex(
ValueError,
"invalid Flag 'Bizarre': aliases b and d are missing combined values of 0x3 .use `enum.show_flag_values.value.` for details.",
"invalid Flag 'Bizarre': aliases b and d are missing combined values of 0x3 .use enum.show_flag_values.value. for details.",
):
@verify(NAMED_FLAGS)
class Bizarre(Flag):
Expand All @@ -3610,7 +3633,7 @@ class Bizarre(IntFlag):
self.assertEqual(Bizarre.d.value, 6)
with self.assertRaisesRegex(
ValueError,
"invalid Flag 'Bizarre': alias d is missing value 0x2 .use `enum.show_flag_values.value.` for details.",
"invalid Flag 'Bizarre': alias d is missing value 0x2 .use enum.show_flag_values.value. for details.",
):
@verify(NAMED_FLAGS)
class Bizarre(IntFlag):
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ Andrew Kuchling
Jakub Kuczys
Dave Kuhlman
Jon Kuhn
Andrei Kulakov
Ilya Kulakov
Upendra Kumar
Toshio Kuratomi
Expand Down

0 comments on commit 41c2a4a

Please sign in to comment.