Skip to content

Commit 4465df6

Browse files
_auto_called cleanup (pythonGH-22285)
(cherry picked from commit fc23a94) Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
1 parent 48f9925 commit 4465df6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Lib/enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def __setitem__(self, key, value):
104104
# enum overwriting a descriptor?
105105
raise TypeError('%r already defined as: %r' % (key, self[key]))
106106
if isinstance(value, auto):
107-
self._auto_called = True
108107
if value.value == _auto_null:
109108
value.value = self._generate_next_value(key, 1, len(self._member_names), self._last_values[:])
109+
self._auto_called = True
110110
value = value.value
111111
self._member_names.append(key)
112112
self._last_values.append(value)

Lib/test/test_enum.py

+11
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,17 @@ class Color(Enum):
18131813
def _generate_next_value_(name, start, count, last):
18141814
return name
18151815

1816+
def test_auto_order_wierd(self):
1817+
weird_auto = auto()
1818+
weird_auto.value = 'pathological case'
1819+
class Color(Enum):
1820+
red = weird_auto
1821+
def _generate_next_value_(name, start, count, last):
1822+
return name
1823+
blue = auto()
1824+
self.assertEqual(list(Color), [Color.red, Color.blue])
1825+
self.assertEqual(Color.red.value, 'pathological case')
1826+
self.assertEqual(Color.blue.value, 'blue')
18161827

18171828
def test_duplicate_auto(self):
18181829
class Dupes(Enum):

0 commit comments

Comments
 (0)