10000 [3.12] gh-119011: `type.__type_params__` now return an empty tuple (G… · python/cpython@7f06cd3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f06cd3

Browse files
[3.12] gh-119011: type.__type_params__ now return an empty tuple (GH-119296) (#119681)
(cherry picked from commit 6b240c2) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent 08636c1 commit 7f06cd3

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

Lib/test/test_functools.py

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

708+
def test_update_type_wrapper(self):
709+
def wrapper(*args): pass
710+
711+
functools.update_wrapper(wrapper, type)
712+
self.assertEqual(wrapper.__name__, 'type')
713+
self.assertEqual(wrapper.__annotations__, {})
714+
self.assertEqual(wrapper.__type_params__, ())
715+
708716

709717
class TestWraps(TestUpdateWrapper):
710718

Lib/test/test_type_params.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@ class C[T]:
499499
r"Cannot use [a-z]+ in annotation scope within class scope"):
500500
run_code(code.format(case))
501501

502+
def test_type_special_case(self):
503+
# https://github.com/python/cpython/issues/119011
504+
self.assertEqual(type.__type_params__, ())
505+
self.assertEqual(object.__type_params__, ())
506+
502507

503508
def make_base(arg):
504509
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,11 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
15061506
static PyObject *
15071507
type_get_type_params(PyTypeObject * 7EA3 type, void *context)
15081508
{
1509-
PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
1509+
if (type == &PyType_Type) {
1510+
return PyTuple_New(0);
1511+
}
15101512

1513+
PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
15111514
if (params) {
15121515
return Py_NewRef(params);
15131516
}

0 commit comments

Comments
 (0)
0