diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-11-19 14:12:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-19 14:12:06 (GMT) |
commit | 6c3b471c8c0bfd49c664d8ee7e95da3710fd6069 (patch) | |
tree | 4efdf0854da2796f9c5f25b8ac41807f1ae0d2cc /Objects/genobject.c | |
parent | c749326d24bf407a18350f9753e75aa5564483c2 (diff) | |
download | cpython-6c3b471c8c0bfd49c664d8ee7e95da3710fd6069.zip cpython-6c3b471c8c0bfd49c664d8ee7e95da3710fd6069.tar.gz cpython-6c3b471c8c0bfd49c664d8ee7e95da3710fd6069.tar.bz2 |
bpo-35409: Ignore GeneratorExit in async_gen_athrow_throw (GH-14755)
Ignore `GeneratorExit` exceptions when throwing an exception into the `aclose` coroutine of an asynchronous generator.
https://bugs.python.org/issue35409
(cherry picked from commit 8e0de2a4808d7c2f4adedabff89ee64e0338790a)
Co-authored-by: Vincent Michel <vxgmichel@gmail.com>
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r-- | Objects/genobject.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c index 6285219..5643553 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1947,6 +1947,17 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *args) PyErr_SetString(PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG); return NULL; } + if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || + PyErr_ExceptionMatches(PyExc_GeneratorExit)) + { + /* when aclose() is called we don't want to propagate + StopAsyncIteration or GeneratorExit; just raise + StopIteration, signalling that this 'aclose()' await + is done. + */ + PyErr_Clear(); + PyErr_SetNone(PyExc_StopIteration); + } return retval; } } |