mirror of
https://github.com/python/cpython.git
synced 2026-02-05 09:25:35 +00:00
bpo-38978: Implement __class_getitem__ for asyncio objects (GH-17491)
https://bugs.python.org/issue38978
This commit is contained in:
parent
723f71abf7
commit
dec367261e
5 changed files with 26 additions and 0 deletions
|
|
@ -1381,6 +1381,12 @@ FutureObj_finalize(FutureObj *fut)
|
|||
PyErr_Restore(error_type, error_value, error_traceback);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
future_cls_getitem(PyObject *cls, PyObject *type)
|
||||
{
|
||||
Py_INCREF(cls);
|
||||
return cls;
|
||||
}
|
||||
|
||||
static PyAsyncMethods FutureType_as_async = {
|
||||
(unaryfunc)future_new_iter, /* am_await */
|
||||
|
|
@ -1400,6 +1406,7 @@ static PyMethodDef FutureType_methods[] = {
|
|||
_ASYNCIO_FUTURE_DONE_METHODDEF
|
||||
_ASYNCIO_FUTURE_GET_LOOP_METHODDEF
|
||||
_ASYNCIO_FUTURE__REPR_INFO_METHODDEF
|
||||
{"__class_getitem__", future_cls_getitem, METH_O|METH_CLASS, NULL},
|
||||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
|
@ -2429,6 +2436,13 @@ TaskObj_finalize(TaskObj *task)
|
|||
FutureObj_finalize((FutureObj*)task);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
task_cls_getitem(PyObject *cls, PyObject *type)
|
||||
{
|
||||
Py_INCREF(cls);
|
||||
return cls;
|
||||
}
|
||||
|
||||
static void TaskObj_dealloc(PyObject *); /* Needs Task_CheckExact */
|
||||
|
||||
static PyMethodDef TaskType_methods[] = {
|
||||
|
|
@ -2449,6 +2463,7 @@ static PyMethodDef TaskType_methods[] = {
|
|||
_ASYNCIO_TASK_GET_NAME_METHODDEF
|
||||
_ASYNCIO_TASK_SET_NAME_METHODDEF
|
||||
_ASYNCIO_TASK_GET_CORO_METHODDEF
|
||||
{"__class_getitem__", task_cls_getitem, METH_O|METH_CLASS, NULL},
|
||||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue