]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104809)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 23 May 2023 19:48:20 +0000 (12:48 -0700)
committerGitHub <noreply@github.com>
Tue, 23 May 2023 19:48:20 +0000 (12:48 -0700)
[3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104279)
(cherry picked from commit f4e2049f14d40c1b893c68530eec5e341cf3d929)

Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
Lib/enum.py
Lib/test/test_enum.py

index 26e5c50bf8563c5a6cf79a299faa5d0fdc020554..45e3cd0b95d9b8527a5c4902126523ac47268c35 100644 (file)
@@ -1170,7 +1170,7 @@ class Enum(metaclass=EnumType):
                     DeprecationWarning,
                     stacklevel=3,
                     )
-            for v in last_values:
+            for v in reversed(last_values):
                 try:
                     return v + 1
                 except TypeError:
index 188e1a1747565f72dcf3471a2259ab162b10c4e6..f5cefa2f3520266f3ebc44bfeb1f09c0c627c7eb 100644 (file)
@@ -4176,11 +4176,14 @@ class TestInternals(unittest.TestCase):
                 red = 'red'
                 blue = 2
                 green = auto()
+                yellow = auto()
 
-        self.assertEqual(list(Color), [Color.red, Color.blue, Color.green])
+        self.assertEqual(list(Color),
+                         [Color.red, Color.blue, Color.green, Color.yellow])
         self.assertEqual(Color.red.value, 'red')
         self.assertEqual(Color.blue.value, 2)
         self.assertEqual(Color.green.value, 3)
+        self.assertEqual(Color.yellow.value, 4)
 
     @unittest.skipIf(
             python_version < (3, 13),