8000 gh-119011: `type.__type_params__` now return an empty tuple (#119296) · python/cpython@6b240c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b240c2

Browse files
authored
gh-119011: type.__type_params__ now return an empty tuple (#119296)
1 parent ae11d68 commit 6b240c2

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
@@ -1848,6 +1848,10 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
18481848
static PyObject *
18491849
type_get_type_params(PyTypeObject *type, void *context)
18501850
{
1851+
if (type == &PyType_Type) {
1852+
return PyTuple_New(0);
1853+
}
1854+
18511855
PyObject *params;
18521856
if (PyDict_GetItemRef(lookup_tp_dict(type), &_Py_ID(__type_params__), &params) == 0) {
18531857
return PyTuple_New(0);

0 commit comments

Comments
 (0)
0