From 09bfba4785d031472c181f19aa335c8fcd034ad1 Mon Sep 17 00:00:00 2001 From: Itamar Ostricher Date: Sun, 7 May 2023 14:13:03 -0700 Subject: [PATCH] gh-104271: Fix auto() fallback in case of mixed type Enum --- 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 6e497f7ef6a7de..bb71c84bd46373 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -1185,7 +1185,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 fb7a016c9007f8..98010d18c0adb2 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -4254,11 +4254,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),