]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104279)
authorItamar Ostricher <itamarost@gmail.com>
Tue, 23 May 2023 18:11:35 +0000 (11:11 -0700)
committerGitHub <noreply@github.com>
Tue, 23 May 2023 18:11:35 +0000 (11:11 -0700)
gh-104271: Fix auto() fallback in case of mixed type Enum

Lib/enum.py
Lib/test/test_enum.py

index 6e497f7ef6a7de134901e2615ccc0280e15d8cf1..bb71c84bd46373f23e144a11e3db530c3a9959ac 100644 (file)
@@ -1185,7 +1185,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 fb7a016c9007f8d444489834f0c8c46c57c6de27..98010d18c0adb2389389f0c0174653095afe3cd7 100644 (file)
@@ -4254,11 +4254,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),