From 582aadc80e566fe8ab9b15d4d221e1ea84d03c6a Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 23 May 2023 12:48:20 -0700 Subject: [PATCH] [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 --- Lib/enum.py | 2 +- Lib/test/test_enum.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/enum.py b/Lib/enum.py index 26e5c50bf8563c..45e3cd0b95d9b8 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 188e1a1747565f..f5cefa2f352026 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),