gh-79940: add introspection API for asynchronous generators to inspect module (#11590)

This commit is contained in:
Thomas Krennwallner 2023-03-11 08:19:40 -05:00 committed by GitHub
parent aa0a73d1bc
commit ced13c96a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 199 additions and 2 deletions

View file

@ -1520,6 +1520,15 @@ ag_getcode(PyGenObject *gen, void *Py_UNUSED(ignored))
return _gen_getcode(gen, "ag_code");
}
static PyObject *
ag_getsuspended(PyAsyncGenObject *ag, void *Py_UNUSED(ignored))
{
if (ag->ag_frame_state == FRAME_SUSPENDED) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}
static PyGetSetDef async_gen_getsetlist[] = {
{"__name__", (getter)gen_get_name, (setter)gen_set_name,
PyDoc_STR("name of the async generator")},
@ -1529,6 +1538,7 @@ static PyGetSetDef async_gen_getsetlist[] = {
PyDoc_STR("object being awaited on, or None")},
{"ag_frame", (getter)ag_getframe, NULL, NULL},
{"ag_code", (getter)ag_getcode, NULL, NULL},
{"ag_suspended", (getter)ag_getsuspended, NULL, NULL},
{NULL} /* Sentinel */
};