mirror of https://github.com/python/cpython
gh-119011: `type.__type_params__` now return an empty tuple (#119296)
This commit is contained in:
parent
ae11d68ab9
commit
6b240c2308
|
@ -710,6 +710,14 @@ class TestUpdateWrapper(unittest.TestCase):
|
||||||
self.assertTrue(wrapper.__doc__.startswith('max('))
|
self.assertTrue(wrapper.__doc__.startswith('max('))
|
||||||
self.assertEqual(wrapper.__annotations__, {})
|
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):
|
class TestWraps(TestUpdateWrapper):
|
||||||
|
|
||||||
|
|
|
@ -563,6 +563,11 @@ class TypeParamsAccessTest(unittest.TestCase):
|
||||||
self.assertIs(T, C.Alias.__type_params__[0])
|
self.assertIs(T, C.Alias.__type_params__[0])
|
||||||
self.assertIs(U, C.__type_params__[1])
|
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):
|
def make_base(arg):
|
||||||
class Base:
|
class Base:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fixes ``type.__type_params__`` to return an empty tuple instead of a
|
||||||
|
descriptor.
|
|
@ -1848,6 +1848,10 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
type_get_type_params(PyTypeObject *type, void *context)
|
type_get_type_params(PyTypeObject *type, void *context)
|
||||||
{
|
{
|
||||||
|
if (type == &PyType_Type) {
|
||||||
|
return PyTuple_New(0);
|
||||||
|
}
|
||||||
|
|
||||||
PyObject *params;
|
PyObject *params;
|
||||||
if (PyDict_GetItemRef(lookup_tp_dict(type), &_Py_ID(__type_params__), ¶ms) == 0) {
|
if (PyDict_GetItemRef(lookup_tp_dict(type), &_Py_ID(__type_params__), ¶ms) == 0) {
|
||||||
return PyTuple_New(0);
|
return PyTuple_New(0);
|
||||||
|
|
Loading…
Reference in New Issue