GH-96704: Add {Task,Handle}.get_context(), use it in call_exception_handler() (#96756)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
Guido van Rossum 2022-10-04 23:49:10 -07:00 • committed by GitHub
parent c70c8b6976
commit 8079bef56f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 129 additions and 2 deletions

View file

@ -2409,6 +2409,18 @@ _asyncio_Task_get_coro_impl(TaskObj *self)
return self->task_coro;
}
/*[clinic input]
_asyncio.Task.get_context
[clinic start generated code]*/
static PyObject *
_asyncio_Task_get_context_impl(TaskObj *self)
/*[clinic end generated code: output=6996f53d3dc01aef input=87c0b209b8fceeeb]*/
{
Py_INCREF(self->task_context);
return self->task_context;
}
/*[clinic input]
_asyncio.Task.get_name
[clinic start generated code]*/
@ -2536,6 +2548,7 @@ static PyMethodDef TaskType_methods[] = {
_ASYNCIO_TASK_GET_NAME_METHODDEF
_ASYNCIO_TASK_SET_NAME_METHODDEF
_ASYNCIO_TASK_GET_CORO_METHODDEF
_ASYNCIO_TASK_GET_CONTEXT_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{NULL, NULL} /* Sentinel */
};

View file

@ -772,6 +772,23 @@ _asyncio_Task_get_coro(TaskObj *self, PyObject *Py_UNUSED(ignored))
return _asyncio_Task_get_coro_impl(self);
}
PyDoc_STRVAR(_asyncio_Task_get_context__doc__,
"get_context($self, /)\n"
"--\n"
"\n");
#define _ASYNCIO_TASK_GET_CONTEXT_METHODDEF \
{"get_context", (PyCFunction)_asyncio_Task_get_context, METH_NOARGS, _asyncio_Task_get_context__doc__},
static PyObject *
_asyncio_Task_get_context_impl(TaskObj *self);
static PyObject *
_asyncio_Task_get_context(TaskObj *self, PyObject *Py_UNUSED(ignored))
{
return _asyncio_Task_get_context_impl(self);
}
PyDoc_STRVAR(_asyncio_Task_get_name__doc__,
"get_name($self, /)\n"
"--\n"
@ -1172,4 +1189,4 @@ _asyncio__leave_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
exit:
return return_value;
}
/*[clinic end generated code: output=459a7c7f21bbc290 input=a9049054013a1b77]*/
/*[clinic end generated code: output=f117b2246eaf7a55 input=a9049054013a1b77]*/