Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,14 @@ def wrapper():
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):

Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_type_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ class C[T]:
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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes ``type.__type_params__`` to return an empty tuple instead of a
descriptor.
5 changes: 4 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down