summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2024-05-28 19:54:47 (GMT)
committerGitHub <noreply@github.com>2024-05-28 19:54:47 (GMT)
commit7f06cd335e91b0ec79c4608f23018c2a785332b1 (patch)
treea88dee77eae8c1c687f880b24a80bdb2a9a42a64
parent08636c1a7d514a4d1d555b1fa903d985b47e8875 (diff)
downloadcpython-7f06cd335e91b0ec79c4608f23018c2a785332b1.zip
cpython-7f06cd335e91b0ec79c4608f23018c2a785332b1.tar.gz
cpython-7f06cd335e91b0ec79c4608f23018c2a785332b1.tar.bz2
[3.12] gh-119011: `type.__type_params__` now return an empty tuple (GH-119296) (#119681)
(cherry picked from commit 6b240c2308a044e38623900ccb8fa58c3549d4ae) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
-rw-r--r--Lib/test/test_functools.py8
-rw-r--r--Lib/test/test_type_params.py5
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2024-05-21-09-46-51.gh-issue-119011.WOe3bu.rst2
-rw-r--r--Objects/typeobject.c5
4 files changed, 19 insertions, 1 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index b73e487..7f1b80a 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -705,6 +705,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):
diff --git a/Lib/test/test_type_params.py b/Lib/test/test_type_params.py
index 3841631..ad5339e 100644
--- a/Lib/test/test_type_params.py
+++ b/Lib/test/test_type_params.py
@@ -499,6 +499,11 @@ class TypeParamsAccessTest(unittest.TestCase):
r"Cannot use [a-z]+ in annotation scope within class scope"):
run_code(code.format(case))
+ 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
index 0000000..0083c18
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2024-05-21-09-46-51.gh-issue-119011.WOe3bu.rst
@@ -0,0 +1,2 @@
+Fixes ``type.__type_params__`` to return an empty tuple instead of a
+descriptor.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 0a21ec8..bf2be42 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1506,8 +1506,11 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
static PyObject *
type_get_type_params(PyTypeObject *type, void *context)
{
- PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
+ if (type == &PyType_Type) {
+ return PyTuple_New(0);
+ }
+ PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
if (params) {
return Py_NewRef(params);
}