diff options
author | Ofey Chan <ofey206@gmail.com> | 2022-09-30 08:43:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-30 08:43:02 (GMT) |
commit | 83a3de4e0632d90e0d1d5a9b8859a94c9ac25f65 (patch) | |
tree | 31d942b63699bc5e1848ffb6f85901fe8b93301c /Objects | |
parent | 9a11ed8e50492d327e4de0a8f3a473e788b14a6f (diff) | |
download | cpython-83a3de4e0632d90e0d1d5a9b8859a94c9ac25f65.zip cpython-83a3de4e0632d90e0d1d5a9b8859a94c9ac25f65.tar.gz cpython-83a3de4e0632d90e0d1d5a9b8859a94c9ac25f65.tar.bz2 |
gh-96348: Deprecate the 3-arg signature of coroutine.throw and generator.throw (GH-96428)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/genobject.c | 32 | ||||
-rw-r--r-- | Objects/iterobject.c | 9 |
2 files changed, 36 insertions, 5 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c index da4afec..ad4fbed 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -418,7 +418,9 @@ PyDoc_STRVAR(throw_doc, throw(type[,value[,tb]])\n\ \n\ Raise exception in generator, return next yielded value or raise\n\ -StopIteration."); +StopIteration.\n\ +the (type, val, tb) signature is deprecated, \n\ +and may be removed in a future version of Python."); static PyObject * _gen_throw(PyGenObject *gen, int close_on_genexit, @@ -559,6 +561,14 @@ gen_throw(PyGenObject *gen, PyObject *const *args, Py_ssize_t nargs) if (!_PyArg_CheckPositional("throw", nargs, 1, 3)) { return NULL; } + if (nargs > 1) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "the (type, exc, tb) signature of throw() is deprecated, " + "use the single-arg signature instead.", + 1) < 0) { + return NULL; + } + } typ = args[0]; if (nargs == 3) { val = args[1]; @@ -1147,7 +1157,10 @@ PyDoc_STRVAR(coro_throw_doc, throw(type[,value[,traceback]])\n\ \n\ Raise exception in coroutine, return next iterated value or raise\n\ -StopIteration."); +StopIteration.\n\ +the (type, val, tb) signature is deprecated, \n\ +and may be removed in a future version of Python."); + PyDoc_STRVAR(coro_close_doc, "close() -> raise GeneratorExit inside coroutine."); @@ -1500,6 +1513,14 @@ async_gen_aclose(PyAsyncGenObject *o, PyObject *arg) static PyObject * async_gen_athrow(PyAsyncGenObject *o, PyObject *args) { + if (PyTuple_GET_SIZE(args) > 1) { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "the (type, exc, tb) signature of athrow() is deprecated, " + "use the single-arg signature instead.", + 1) < 0) { + return NULL; + } + } if (async_gen_init_hooks(o)) { return NULL; } @@ -1537,7 +1558,12 @@ PyDoc_STRVAR(async_asend_doc, "asend(v) -> send 'v' in generator."); PyDoc_STRVAR(async_athrow_doc, -"athrow(typ[,val[,tb]]) -> raise exception in generator."); +"athrow(value)\n\ +athrow(type[,value[,tb]])\n\ +\n\ +raise exception in generator.\n\ +the (type, val, tb) signature is deprecated, \n\ +and may be removed in a future version of Python."); static PyMethodDef async_gen_methods[] = { {"asend", (PyCFunction)async_gen_asend, METH_O, async_asend_doc}, diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 1732a03..62c3614 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -428,8 +428,13 @@ return next yielded value or raise StopIteration."); PyDoc_STRVAR(throw_doc, -"throw(typ[,val[,tb]]) -> raise exception in the wrapped iterator,\n\ -return next yielded value or raise StopIteration."); +"throw(value)\n\ +throw(typ[,val[,tb]])\n\ +\n\ +raise exception in the wrapped iterator, return next yielded value\n\ +or raise StopIteration.\n\ +the (type, val, tb) signature is deprecated, \n\ +and may be removed in a future version of Python."); PyDoc_STRVAR(close_doc, |