[Python-checkins] [3.11] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104809)

ethanfurman webhook-mailer at python.org
Tue May 23 15:48:28 EDT 2023


https://github.com/python/cpython/commit/582aadc80e566fe8ab9b15d4d221e1ea84d03c6a
commit: 582aadc80e566fe8ab9b15d4d221e1ea84d03c6a
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2023-05-23T12:48:20-07:00
summary:

[3.11] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104809)

[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 at gmail.com>

files:
M Lib/enum.py
M Lib/test/test_enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index 26e5c50bf856..45e3cd0b95d9 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -1170,7 +1170,7 @@ def _generate_next_value_(name, start, count, last_values):
                     DeprecationWarning,
                     stacklevel=3,
                     )
-            for v in last_values:
+            for v in reversed(last_values):
                 try:
                     return v + 1
                 except TypeError:
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 188e1a174756..f5cefa2f3520 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -4176,11 +4176,14 @@ class Color(Enum):
                 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),



More information about the Python-checkins mailing list