bpo-36933: Remove sys.set_coroutine_wrapper (marked for removal in 3.8) (GH-13577)

It has been documented as deprecated and to be removed in 3.8; 

From a comment on another thread – which I can't find ; leave get_coro_wrapper() for now, but always return `None`.


https://bugs.python.org/issue36933
This commit is contained in:
Matthias Bussonnier 2019-05-28 00:10:59 -07:00 committed by Miss Islington (bot)
parent 436c2b0d67
commit 3880f263d2
11 changed files with 7 additions and 287 deletions

View file

@ -4143,19 +4143,8 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
/* Handle generator/coroutine/asynchronous generator */
if (co->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
PyObject *gen;
PyObject *coro_wrapper = tstate->coroutine_wrapper;
int is_coro = co->co_flags & CO_COROUTINE;
if (is_coro && tstate->in_coroutine_wrapper) {
assert(coro_wrapper != NULL);
_PyErr_Format(tstate, PyExc_RuntimeError,
"coroutine wrapper %.200R attempted "
"to recursively wrap %.200R",
coro_wrapper,
co);
goto fail;
}
/* Don't need to keep the reference to f_back, it will be set
* when the generator is resumed. */
Py_CLEAR(f->f_back);
@ -4175,14 +4164,6 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
_PyObject_GC_TRACK(f);
if (is_coro && coro_wrapper != NULL) {
PyObject *wrapped;
tstate->in_coroutine_wrapper = 1;
wrapped = PyObject_CallFunction(coro_wrapper, "N", gen);
tstate->in_coroutine_wrapper = 0;
return wrapped;
}
return gen;
}
@ -4633,26 +4614,6 @@ _PyEval_GetCoroutineOriginTrackingDepth(void)
return tstate->coroutine_origin_tracking_depth;
}
void
_PyEval_SetCoroutineWrapper(PyObject *wrapper)
{
PyThreadState *tstate = _PyThreadState_GET();
if (PySys_Audit("sys.set_coroutine_wrapper", NULL) < 0) {
return;
}
Py_XINCREF(wrapper);
Py_XSETREF(tstate->coroutine_wrapper, wrapper);
}
PyObject *
_PyEval_GetCoroutineWrapper(void)
{
PyThreadState *tstate = _PyThreadState_GET();
return tstate->coroutine_wrapper;
}
void
_PyEval_SetAsyncGenFirstiter(PyObject *firstiter)
{

View file

@ -510,33 +510,6 @@ exit:
return return_value;
}
PyDoc_STRVAR(sys_set_coroutine_wrapper__doc__,
"set_coroutine_wrapper($module, wrapper, /)\n"
"--\n"
"\n"
"Set a wrapper for coroutine objects.");
#define SYS_SET_COROUTINE_WRAPPER_METHODDEF \
{"set_coroutine_wrapper", (PyCFunction)sys_set_coroutine_wrapper, METH_O, sys_set_coroutine_wrapper__doc__},
PyDoc_STRVAR(sys_get_coroutine_wrapper__doc__,
"get_coroutine_wrapper($module, /)\n"
"--\n"
"\n"
"Return the wrapper for coroutines set by sys.set_coroutine_wrapper.");
#define SYS_GET_COROUTINE_WRAPPER_METHODDEF \
{"get_coroutine_wrapper", (PyCFunction)sys_get_coroutine_wrapper, METH_NOARGS, sys_get_coroutine_wrapper__doc__},
static PyObject *
sys_get_coroutine_wrapper_impl(PyObject *module);
static PyObject *
sys_get_coroutine_wrapper(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return sys_get_coroutine_wrapper_impl(module);
}
PyDoc_STRVAR(sys_get_asyncgen_hooks__doc__,
"get_asyncgen_hooks($module, /)\n"
"--\n"
@ -1109,4 +1082,4 @@ sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
#define SYS_GETANDROIDAPILEVEL_METHODDEF
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
/*[clinic end generated code: output=03da2eb03135d9f2 input=a9049054013a1b77]*/
/*[clinic end generated code: output=43c4fde7b5783d8d input=a9049054013a1b77]*/

View file

@ -606,9 +606,6 @@ new_threadstate(PyInterpreterState *interp, int init)
tstate->coroutine_origin_tracking_depth = 0;
tstate->coroutine_wrapper = NULL;
tstate->in_coroutine_wrapper = 0;
tstate->async_gen_firstiter = NULL;
tstate->async_gen_finalizer = NULL;
@ -802,7 +799,6 @@ PyThreadState_Clear(PyThreadState *tstate)
Py_CLEAR(tstate->c_profileobj);
Py_CLEAR(tstate->c_traceobj);
Py_CLEAR(tstate->coroutine_wrapper);
Py_CLEAR(tstate->async_gen_firstiter);
Py_CLEAR(tstate->async_gen_finalizer);

View file

@ -1158,62 +1158,6 @@ sys_get_coroutine_origin_tracking_depth_impl(PyObject *module)
return _PyEval_GetCoroutineOriginTrackingDepth();
}
/*[clinic input]
sys.set_coroutine_wrapper
wrapper: object
/
Set a wrapper for coroutine objects.
[clinic start generated code]*/
static PyObject *
sys_set_coroutine_wrapper(PyObject *module, PyObject *wrapper)
/*[clinic end generated code: output=9c7db52d65f6b188 input=df6ac09a06afef34]*/
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"set_coroutine_wrapper is deprecated", 1) < 0) {
return NULL;
}
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_RETURN_NONE;
}
/*[clinic input]
sys.get_coroutine_wrapper
Return the wrapper for coroutines set by sys.set_coroutine_wrapper.
[clinic start generated code]*/
static PyObject *
sys_get_coroutine_wrapper_impl(PyObject *module)
/*[clinic end generated code: output=b74a7e4b14fe898e input=ef0351fb9ece0bb4]*/
{
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"get_coroutine_wrapper is deprecated", 1) < 0) {
return NULL;
}
PyObject *wrapper = _PyEval_GetCoroutineWrapper();
if (wrapper == NULL) {
wrapper = Py_None;
}
Py_INCREF(wrapper);
return wrapper;
}
static PyTypeObject AsyncGenHooksType;
PyDoc_STRVAR(asyncgen_hooks_doc,
@ -2002,8 +1946,6 @@ static PyMethodDef sys_methods[] = {
SYS__DEBUGMALLOCSTATS_METHODDEF
SYS_SET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF
SYS_GET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF
SYS_SET_COROUTINE_WRAPPER_METHODDEF
SYS_GET_COROUTINE_WRAPPER_METHODDEF
{"set_asyncgen_hooks", (PyCFunction)(void(*)(void))sys_set_asyncgen_hooks,
METH_VARARGS | METH_KEYWORDS, set_asyncgen_hooks_doc},
SYS_GET_ASYNCGEN_HOOKS_METHODDEF