PEP 0492 -- Coroutines with async and await syntax. Issue #24017.

This commit is contained in:
Yury Selivanov 2015-05-11 22:57:16 -04:00
parent 4e6bf4b3da
commit 7544508f02
72 changed files with 9261 additions and 5739 deletions

View file

@ -645,6 +645,49 @@ sys_setrecursionlimit(PyObject *self, PyObject *args)
return Py_None;
}
static PyObject *
sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper)
{
if (wrapper != Py_None) {
if (!PyCallable_Check(wrapper)) {
PyErr_Format(PyExc_TypeError,
"callable expected, got %.50s",
Py_TYPE(wrapper)->tp_name);
return NULL;
}
PyEval_SetCoroutineWrapper(wrapper);
}
else
PyEval_SetCoroutineWrapper(NULL);
Py_INCREF(Py_None);
Py_RETURN_NONE;
}
PyDoc_STRVAR(set_coroutine_wrapper_doc,
"set_coroutine_wrapper(wrapper)\n\
\n\
Set a wrapper for coroutine objects."
);
static PyObject *
sys_get_coroutine_wrapper(PyObject *self, PyObject *args)
{
PyObject *wrapper = PyEval_GetCoroutineWrapper();
if (wrapper == NULL) {
wrapper = Py_None;
}
Py_INCREF(wrapper);
return wrapper;
}
PyDoc_STRVAR(get_coroutine_wrapper_doc,
"get_coroutine_wrapper()\n\
\n\
Return the wrapper for coroutine objects set by sys.set_coroutine_wrapper."
);
static PyTypeObject Hash_InfoType;
PyDoc_STRVAR(hash_info_doc,
@ -1215,6 +1258,10 @@ static PyMethodDef sys_methods[] = {
{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
{"_debugmallocstats", sys_debugmallocstats, METH_NOARGS,
debugmallocstats_doc},
{"set_coroutine_wrapper", sys_set_coroutine_wrapper, METH_O,
set_coroutine_wrapper_doc},
{"get_coroutine_wrapper", sys_get_coroutine_wrapper, METH_NOARGS,
get_coroutine_wrapper_doc},
{NULL, NULL} /* sentinel */
};