From c0e99617985d64e6134964f758ae0a1a20f9f433 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 28 May 2024 21:09:04 +0200 Subject: [3.13] gh-119011: `type.__type_params__` now return an empty tuple (GH-119296) (#119678) (cherry picked from commit 6b240c2308a044e38623900ccb8fa58c3549d4ae) Co-authored-by: Nikita Sobolev --- Lib/test/test_functools.py | 8 ++++++++ Lib/test/test_type_params.py | 5 +++++ .../2024-05-21-09-46-51.gh-issue-119011.WOe3bu.rst | 2 ++ Objects/typeobject.c | 4 ++++ 4 files changed, 19 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-05-21-09-46-51.gh-issue-119011.WOe3bu.rst diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 4a9a731..26701ea 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -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): diff --git a/Lib/test/test_type_params.py b/Lib/test/test_type_params.py index aa9d408..bf1a34b 100644 --- a/Lib/test/test_type_params.py +++ b/Lib/test/test_type_params.py @@ -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 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 4af4971..f588992 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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__), ¶ms) == 0) { return PyTuple_New(0); -- cgit v0.12