mirror of
https://github.com/python/cpython.git
synced 2025-11-07 17:12:03 +00:00
[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 f4e2049f14)
Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
This commit is contained in:
parent
ac12a6bf34
commit
582aadc80e
2 changed files with 5 additions and 2 deletions
|
|
@ -1170,7 +1170,7 @@ def _generate_next_value_(name, start, count, last_values):
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
stacklevel=3,
|
stacklevel=3,
|
||||||
)
|
)
|
||||||
for v in last_values:
|
for v in reversed(last_values):
|
||||||
try:
|
try:
|
||||||
return v + 1
|
return v + 1
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
||||||
|
|
@ -4176,11 +4176,14 @@ class Color(Enum):
|
||||||
red = 'red'
|
red = 'red'
|
||||||
blue = 2
|
blue = 2
|
||||||
green = auto()
|
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.red.value, 'red')
|
||||||
self.assertEqual(Color.blue.value, 2)
|
self.assertEqual(Color.blue.value, 2)
|
||||||
self.assertEqual(Color.green.value, 3)
|
self.assertEqual(Color.green.value, 3)
|
||||||
|
self.assertEqual(Color.yellow.value, 4)
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
python_version < (3, 13),
|
python_version < (3, 13),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue