mirror of
https://github.com/python/cpython.git
synced 2025-08-10 11:58:39 +00:00
[3.12] gh-119011: type.__type_params__
now return an empty tuple (GH-119296) (#119681)
(cherry picked from commit 6b240c2308
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
08636c1a7d
commit
7f06cd335e
4 changed files with 19 additions and 1 deletions
|
@ -705,6 +705,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):
|
||||
|
||||
|
|
|
@ -499,6 +499,11 @@ class TypeParamsAccessTest(unittest.TestCase):
|
|||
r"Cannot use [a-z]+ in annotation scope within class scope"):
|
||||
run_code(code.format(case))
|
||||
|
||||
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:
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fixes ``type.__type_params__`` to return an empty tuple instead of a
|
||||
descriptor.
|
|
@ -1506,8 +1506,11 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
|
|||
static PyObject *
|
||||
type_get_type_params(PyTypeObject *type, void *context)
|
||||
{
|
||||
PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
|
||||
if (type == &PyType_Type) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
|
||||
PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
|
||||
if (params) {
|
||||
return Py_NewRef(params);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue