Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-…
…104279)

(cherry picked from commit f4e2049)

Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
gh-104271: Fix auto() fallback in case of mixed type Enum
  • Loading branch information
itamaro authored and miss-islington committed May 23, 2023
commit 10939d32fecc97d753b3178576db0f597d51a276
2 changes: 1 addition & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down