8000 [3.13] gh-119011: `type.__type_params__` now return an empty tuple (GH-119296) by miss-islington · Pull Request #119678 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.13] gh-119011: type.__type_params__ now return an empty tuple (GH-119296) #119678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2024
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 @@ -710,6 +710,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 @@ -563,6 +563,11 @@ class C[T, U]:
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:
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.
4 changes: 4 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,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);
Expand Down
Loading
0