Skip to content

Commit

Permalink
replace athrow().close() and asend().close() stubs with implimentations
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Apr 15, 2024
1 parent 3131a70 commit d5d0867
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,8 +1843,23 @@ 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(PyExc_GeneratorExit);
if (retval == NULL) {
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
PyErr_ExceptionMatches(PyExc_GeneratorExit))
{
PyErr_Clear();
Py_RETURN_NONE;
}
} else {
Py_DECREF(retval);
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
}
}

static void
Expand Down Expand Up @@ -2288,8 +2303,23 @@ 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(PyExc_GeneratorExit);
if (retval == NULL) {
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
PyErr_ExceptionMatches(PyExc_GeneratorExit))
{
PyErr_Clear();
Py_RETURN_NONE;
}
} else {
Py_DECREF(retval);
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
}
}


Expand Down

0 comments on commit d5d0867

Please sign in to comment.