Skip to content

Commit c0e9961

Browse files
[3.13] gh-119011: type.__type_params__ now return an empty tuple (GH-119296) (#119678)
(cherry picked from commit 6b240c2) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent 6394a72 commit c0e9961

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

Lib/test/test_functools.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,14 @@ def wrapper():
710710
self.assertTrue(wrapper.__doc__.startswith('max('))
711711
self.assertEqual(wrapper.__annotations__, {})
712712

713+
def test_update_type_wrapper(self):
714+
def wrapper(*args): pass
715+
716+
functools.update_wrapper(wrapper, type)
717+
self.assertEqual(wrapper.__name__, 'type')
718+
self.assertEqual(wrapper.__annotations__, {})
719+
self.assertEqual(wrapper.__type_params__, ())
720+
713721

714722
class TestWraps(TestUpdateWrapper):
715723

Lib/test/test_type_params.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,11 @@ class C[T, U]:
563563
self.assertIs(T, C.Alias.__type_params__[0])
564564
self.assertIs(U, C.__type_params__[1])
565565

566+
def test_type_special_case(self):
567+
# https://github.com/python/cpython/issues/119011
568+
self.assertEqual(type.__type_params__, ())
569+
self.assertEqual(object.__type_params__, ())
570+
566571

567572
def make_base(arg):
568573
class Base:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes ``type.__type_params__`` to return an empty tuple instead of a
2+
descriptor.

Objects/typeobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,10 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
17421742
static PyObject *
17431743
type_get_type_params(PyTypeObject *type, void *context)
17441744
{
1745+
if (type == &PyType_Type) {
1746+
return PyTuple_New(0);
1747+
}
1748+
17451749
PyObject *params;
17461750
if (PyDict_GetItemRef(lookup_tp_dict(type), &_Py_ID(__type_params__), &params) == 0) {
17471751
return PyTuple_New(0);

0 commit comments

Comments
 (0)