]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-119011: `type.__type_params__` now return an empty tuple (#119296)
authorNikita Sobolev <mail@sobolevn.me>
Tue, 28 May 2024 18:12:58 +0000 (21:12 +0300)
committerGitHub <noreply@github.com>
Tue, 28 May 2024 18:12:58 +0000 (18:12 +0000)
Lib/test/test_functools.py
Lib/test/test_type_params.py
Misc/NEWS.d/next/Core and Builtins/2024-05-21-09-46-51.gh-issue-119011.WOe3bu.rst [new file with mode: 0644]
Objects/typeobject.c

index 4a9a7313712f602b9207dedcf12259081d3e29be..26701ea8b4daf9445e2e1fd8d4a40c6aa5a4a2d0 100644 (file)
@@ -710,6 +710,14 @@ class TestUpdateWrapper(unittest.TestCase):
         self.assertTrue(wrapper.__doc__.startswith('max('))
         self.assertEqual(wrapper.__annotations__, {})
 
+    def test_update_type_wrapper(self):
+        def wrapper(*args): pass
+
+        functools.update_wrapper(wrapper, type)
+        self.assertEqual(wrapper.__name__, 'type')
+        self.assertEqual(wrapper.__annotations__, {})
+        self.assertEqual(wrapper.__type_params__, ())
+
 
 class TestWraps(TestUpdateWrapper):
 
index aa9d4088bd7ccc3ec18a730cd1d52445b3aa2c33..bf1a34b9fc82b35cdf505d7eae0e77c28ddc5feb 100644 (file)
@@ -563,6 +563,11 @@ class TypeParamsAccessTest(unittest.TestCase):
         self.assertIs(T, C.Alias.__type_params__[0])
         self.assertIs(U, C.__type_params__[1])
 
+    def test_type_special_case(self):
+        # https://github.com/python/cpython/issues/119011
+        self.assertEqual(type.__type_params__, ())
+        self.assertEqual(object.__type_params__, ())
+
 
 def make_base(arg):
     class Base:
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-21-09-46-51.gh-issue-119011.WOe3bu.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-21-09-46-51.gh-issue-119011.WOe3bu.rst
new file mode 100644 (file)
index 0000000..0083c18
--- /dev/null
@@ -0,0 +1,2 @@
+Fixes ``type.__type_params__`` to return an empty tuple instead of a
+descriptor.
index 11f9c570ac497113dcb5ef18c480227f9d91f884..9d849d83082ccd2f7b8f1d32a1d00d7ed71c33b9 100644 (file)
@@ -1848,6 +1848,10 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
 static PyObject *
 type_get_type_params(PyTypeObject *type, void *context)
 {
+    if (type == &PyType_Type) {
+        return PyTuple_New(0);
+    }
+
     PyObject *params;
     if (PyDict_GetItemRef(lookup_tp_dict(type), &_Py_ID(__type_params__), &params) == 0) {
         return PyTuple_New(0);