]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46296: [Enum] add a test for missing `value` recovery (GH-30458)
authorNikita Sobolev <mail@sobolevn.me>
Fri, 7 Jan 2022 21:44:21 +0000 (00:44 +0300)
committerGitHub <noreply@github.com>
Fri, 7 Jan 2022 21:44:21 +0000 (13:44 -0800)
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.

Lib/test/test_enum.py
Misc/NEWS.d/next/Tests/2022-01-08-00-00-38.bpo-46296.vqxgTm.rst [new file with mode: 0644]

index 51a31e5ebf8076b889269238e18d35ed1a91a890..2b3eac56865b1ed769cb25226cd3e142904847f2 100644 (file)
@@ -1022,6 +1022,16 @@ class TestEnum(unittest.TestCase):
             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 (file)
index 0000000..9e0d470
--- /dev/null
@@ -0,0 +1,2 @@
+Add a test case for :mod:`enum`
+with ``_use_args_ == True`` and ``_member_type_ == object``.