mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
GH-117714: implement athrow().close() and asend().close() using throw (GH-117906)
* GH-117714: replace athrow().close() and asend().close() stubs with implimentations * test athrow().close() and asend().close() raises RuntimeError * 📜🤖 Added by blurb_it. * Update Objects/genobject.c Co-authored-by: Petr Viktorin <encukou@gmail.com> --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
1ff626ebda
commit
e5c699280d
3 changed files with 87 additions and 4 deletions
|
|
@ -1846,8 +1846,25 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *const *args, Py_ssize_t narg
|
|||
static PyObject *
|
||||
async_gen_asend_close(PyAsyncGenASend *o, PyObject *args)
|
||||
{
|
||||
o->ags_state = AWAITABLE_STATE_CLOSED;
|
||||
Py_RETURN_NONE;
|
||||
PyObject *result;
|
||||
if (o->ags_state == AWAITABLE_STATE_CLOSED) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
result = async_gen_asend_throw(o, &PyExc_GeneratorExit, 1);
|
||||
if (result == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
|
||||
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
|
||||
PyErr_ExceptionMatches(PyExc_GeneratorExit))
|
||||
{
|
||||
PyErr_Clear();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
Py_DECREF(result);
|
||||
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -2291,8 +2308,25 @@ async_gen_athrow_iternext(PyAsyncGenAThrow *o)
|
|||
static PyObject *
|
||||
async_gen_athrow_close(PyAsyncGenAThrow *o, PyObject *args)
|
||||
{
|
||||
o->agt_state = AWAITABLE_STATE_CLOSED;
|
||||
Py_RETURN_NONE;
|
||||
PyObject *result;
|
||||
if (o->agt_state == AWAITABLE_STATE_CLOSED) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
result = async_gen_athrow_throw(o, &PyExc_GeneratorExit, 1);
|
||||
if (result == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
|
||||
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
|
||||
PyErr_ExceptionMatches(PyExc_GeneratorExit))
|
||||
{
|
||||
PyErr_Clear();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
Py_DECREF(result);
|
||||
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue