]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_auto_called cleanup (GH-22285)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 17 Sep 2020 00:28:32 +0000 (17:28 -0700)
committerGitHub <noreply@github.com>
Thu, 17 Sep 2020 00:28:32 +0000 (17:28 -0700)
(cherry picked from commit fc23a9483ef0d7c98bea9f82392377d0b6ef7b18)

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Lib/enum.py
Lib/test/test_enum.py

index 4c1acc6e360bd76bd4df7a50e9fa07e32fb79f36..c2adfd1c6c0bb72beb298aab85ecae78bf302b71 100644 (file)
@@ -104,9 +104,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 11e88dba6b5b3660a0504ada3b190241feb8e594..daa44ae6824ce0e59b1737212d6df4e57d30e570 100644 (file)
@@ -1815,6 +1815,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):