Skip to content

Commit 41c2a4a

Browse files
authored
[3.10] bpo-44342: [Enum] improve test, add andrei kulakov to ACKS (GH-26726)
* [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 0f99324 commit 41c2a4a

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

Doc/library/enum.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ Data Types
576576
... NEON = 31
577577
Traceback (most recent call last):
578578
...
579-
ValueError: invalid Flag 'Color': 'WHITE' is missing a named flag for value 8; 'NEON' is missing named flags for values 8, 16
579+
ValueError: invalid Flag 'Color': aliases WHITE and NEON are missing combined values of 0x18 [use enum.show_flag_values(value) for details]
580580

581581
.. note::
582582

Lib/enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ def __call__(self, enumeration):
16371637
else:
16381638
value = 'combined values of 0x%x' % missing_value
16391639
raise ValueError(
1640-
'invalid Flag %r: %s %s [use `enum.show_flag_values(value)` for details]'
1640+
'invalid Flag %r: %s %s [use enum.show_flag_values(value) for details]'
16411641
% (cls_name, alias, value)
16421642
)
16431643
return enumeration

Lib/test/test_enum.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,35 @@ def __repr__(self):
660660
self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>')
661661
#
662662
class SillyInt(HexInt):
663+
__qualname__ = 'SillyInt'
663664
pass
664665
class MyOtherEnum(SillyInt, enum.Enum):
666+
__qualname__ = 'MyOtherEnum'
665667
D = 4
666668
E = 5
667669
F = 6
668670
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)
669692

670693
def test_too_many_data_types(self):
671694
with self.assertRaisesRegex(TypeError, 'too many data types'):
@@ -3591,7 +3614,7 @@ class Bizarre(Flag):
35913614
self.assertEqual(Bizarre.d.value, 6)
35923615
with self.assertRaisesRegex(
35933616
ValueError,
3594-
"invalid Flag 'Bizarre': aliases b and d are missing combined values of 0x3 .use `enum.show_flag_values.value.` for details.",
3617+
"invalid Flag 'Bizarre': aliases b and d are missing combined values of 0x3 .use enum.show_flag_values.value. for details.",
35953618
):
35963619
@verify(NAMED_FLAGS)
35973620
class Bizarre(Flag):
@@ -3610,7 +3633,7 @@ class Bizarre(IntFlag):
36103633
self.assertEqual(Bizarre.d.value, 6)
36113634
with self.assertRaisesRegex(
36123635
ValueError,
3613-
"invalid Flag 'Bizarre': alias d is missing value 0x2 .use `enum.show_flag_values.value.` for details.",
3636+
"invalid Flag 'Bizarre': alias d is missing value 0x2 .use enum.show_flag_values.value. for details.",
36143637
):
36153638
@verify(NAMED_FLAGS)
36163639
class Bizarre(IntFlag):

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)