From 10939d32fecc97d753b3178576db0f597d51a276 Mon Sep 17 00:00:00 2001 From: Itamar Ostricher Date: Tue, 23 May 2023 11:11:35 -0700 Subject: [PATCH] [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 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 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), pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy