summaryrefslogtreecommitdiffstats
path: root/Objects/genobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r--Objects/genobject.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 89bb21a..acdcf57 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -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;
+ }
}