[Python-checkins] bpo-46296: [Enum] add a test for missing `value` recovery (GH-30458)

ethanfurman webhook-mailer at python.org
Fri Jan 7 16:44:28 EST 2022


https://github.com/python/cpython/commit/74d1663580d1914bd110c3ab7282451f5e2cd2b5
commit: 74d1663580d1914bd110c3ab7282451f5e2cd2b5
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2022-01-07T13:44:21-08:00
summary:

bpo-46296: [Enum] add a test for missing `value` recovery (GH-30458)

In `__set_name__` there is a check for the `_value_` attribute and an attempt to add it if missing; this adds a test to cover the case for simple enums with a custom `__new__` method.

files:
A Misc/NEWS.d/next/Tests/2022-01-08-00-00-38.bpo-46296.vqxgTm.rst
M Lib/test/test_enum.py

diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 51a31e5ebf807..2b3eac56865b1 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1022,6 +1022,16 @@ def repr(self):
             class Huh(MyStr, MyInt, Enum):
                 One = 1
 
+    def test_value_auto_assign(self):
+        class Some(Enum):
+            def __new__(cls, val):
+                return object.__new__(cls)
+            x = 1
+            y = 2
+
+        self.assertEqual(Some.x.value, 1)
+        self.assertEqual(Some.y.value, 2)
+
     def test_hash(self):
         Season = self.Season
         dates = {}
diff --git a/Misc/NEWS.d/next/Tests/2022-01-08-00-00-38.bpo-46296.vqxgTm.rst b/Misc/NEWS.d/next/Tests/2022-01-08-00-00-38.bpo-46296.vqxgTm.rst
new file mode 100644
index 0000000000000..9e0d470e269cb
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-01-08-00-00-38.bpo-46296.vqxgTm.rst
@@ -0,0 +1,2 @@
+Add a test case for :mod:`enum`
+with ``_use_args_ == True`` and ``_member_type_ == object``.



More information about the Python-checkins mailing list