[Python-checkins] _auto_called cleanup (GH-22285)

Miss Islington (bot) webhook-mailer at python.org
Wed Sep 16 20:27:31 EDT 2020


https://github.com/python/cpython/commit/4465df626684fdc8eeb25ca248218cde2eeeb9ec
commit: 4465df626684fdc8eeb25ca248218cde2eeeb9ec
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-09-16T17:27:09-07:00
summary:

_auto_called cleanup (GH-22285)

(cherry picked from commit fc23a9483ef0d7c98bea9f82392377d0b6ef7b18)

Co-authored-by: Ethan Furman <ethan at stoneleaf.us>

files:
M Lib/enum.py
M Lib/test/test_enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index bdbfbb69bdea6..da5a31f0b88ac 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -104,9 +104,9 @@ def __setitem__(self, key, value):
                 # 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)
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 0ecf6413b1313..6f547165acfee 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1813,6 +1813,17 @@ class Color(Enum):
                 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):



More information about the Python-checkins mailing list