]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-44342: [Enum] improve test, add andrei kulakov to ACKS (GH-26726)
authorEthan Furman <ethan@stoneleaf.us>
Wed, 16 Jun 2021 01:50:59 +0000 (18:50 -0700)
committerGitHub <noreply@github.com>
Wed, 16 Jun 2021 01:50:59 +0000 (18:50 -0700)
* [3.10] [Enum] improve test, add andrei kulakov to ACKS (GH-26726).
(cherry picked from commit cb2014f2077c92c35486bf0db7e646a68478a7a5)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Doc/library/enum.rst
Lib/enum.py
Lib/test/test_enum.py
Misc/ACKS

index 2d19ef6f25657bef1fa2cfed3590be9bf776bbd5..077a35453ae4ce08ea81fd606834701a1d6f8396 100644 (file)
@@ -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::
 
index 49c46ea86dbacfa2b111fbb25c1ab588209a4a63..90777988dd041d10a67502fba038d5a5bf45a51f 100644 (file)
@@ -1637,7 +1637,7 @@ class verify:
                     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
index 956b8347b1e1cb9e40f74ece6e4819cee5e01d43..c4c458e6bfc4ef4d897e6540315dbca3a6b1b9ba 100644 (file)
@@ -660,12 +660,35 @@ class TestEnum(unittest.TestCase):
         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'):
@@ -3591,7 +3614,7 @@ class TestVerify(unittest.TestCase):
         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):
@@ -3610,7 +3633,7 @@ class TestVerify(unittest.TestCase):
         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):
index 0cb738b3a12ee4ce8dcb90975f49d1d5886d1ce7..b1bd33aaa35cf52919e8dfac788619574c7f6467 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -970,6 +970,7 @@ Andrew Kuchling
 Jakub Kuczys
 Dave Kuhlman
 Jon Kuhn
+Andrei Kulakov
 Ilya Kulakov
 Upendra Kumar
 Toshio Kuratomi