Skip to content

Commit fc23a94

Browse files
authored
_auto_called cleanup (GH-22285)
1 parent a5634c4 commit fc23a94

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Lib/enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ def __setitem__(self, key, value):
105105
# enum overwriting a descriptor?
106106
raise TypeError('%r already defined as: %r' % (key, self[key]))
107107
if isinstance(value, auto):
108-
self._auto_called = True
109108
if value.value == _auto_null:
110109
value.value = self._generate_next_value(key, 1, len(self._member_names), self._last_values[:])
110+
self._auto_called = True
111111
value = value.value
112112
self._member_names.append(key)
113113
self._last_values.append(value)

Lib/test/test_enum.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,17 @@ class Color(Enum):
18371837
def _generate_next_value_(name, start, count, last):
18381838
return name
18391839

1840+
def test_auto_order_wierd(self):
1841+
weird_auto = auto()
1842+
weird_auto.value = 'pathological case'
1843+
class Color(Enum):
1844+
red = weird_auto
1845+
def _generate_next_value_(name, start, count, last):
1846+
return name
1847+
blue = auto()
1848+
self.assertEqual(list(Color), [Color.red, Color.blue])
1849+
self.assertEqual(Color.red.value, 'pathological case')
1850+
self.assertEqual(Color.blue.value, 'blue')
18401851

18411852
def test_duplicate_auto(self):
18421853
class Dupes(Enum):

0 commit comments

Comments
 (0)