]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_auto_called cleanup (GH-22285)
authorEthan Furman <ethan@stoneleaf.us>
Wed, 16 Sep 2020 19:37:54 +0000 (12:37 -0700)
committerGitHub <noreply@github.com>
Wed, 16 Sep 2020 19:37:54 +0000 (12:37 -0700)
Lib/enum.py
Lib/test/test_enum.py

index 060b2a0dadf4576cf200599c10b3ca56d76368b3..21a94caaee33f3451096259dcda23adc3c54cea8 100644 (file)
@@ -105,9 +105,9 @@ class _EnumDict(dict):
                 # enum overwriting a descriptor?
                 raise TypeError('%r already defined as: %r' % (key, self[key]))
             if isinstance(value, auto):
-                self._auto_called = True
                 if value.value == _auto_null:
                     value.value = self._generate_next_value(key, 1, len(self._member_names), self._last_values[:])
+                    self._auto_called = True
                 value = value.value
             self._member_names.append(key)
             self._last_values.append(value)
index 5d72d82cec27ffe53ee363b917886d9625e13d63..ebf76047972dc0b7e5cfedb2ff1a119e0e1a2e40 100644 (file)
@@ -1837,6 +1837,17 @@ class TestEnum(unittest.TestCase):
                 def _generate_next_value_(name, start, count, last):
                     return name
 
+    def test_auto_order_wierd(self):
+        weird_auto = auto()
+        weird_auto.value = 'pathological case'
+        class Color(Enum):
+            red = weird_auto
+            def _generate_next_value_(name, start, count, last):
+                return name
+            blue = auto()
+        self.assertEqual(list(Color), [Color.red, Color.blue])
+        self.assertEqual(Color.red.value, 'pathological case')
+        self.assertEqual(Color.blue.value, 'blue')
 
     def test_duplicate_auto(self):
         class Dupes(Enum):