From: Itamar Ostricher Date: Tue, 23 May 2023 18:11:35 +0000 (-0700) Subject: [3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104279) X-Git-Tag: v3.12.0b2~108 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f4e2049f14d40c1b893c68530eec5e341cf3d929;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-104279) gh-104271: Fix auto() fallback in case of mixed type Enum --- diff --git a/Lib/enum.py b/Lib/enum.py index 6e497f7ef6a7..bb71c84bd463 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -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: diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index fb7a016c9007..98010d18c0ad 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -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),