Skip to content

Commit

Permalink
pythonGH-117536: fix athrow().throw(...) unawaited warning
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Apr 13, 2024
1 parent 56ed979 commit da89a69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,17 @@ async def gen():
g.aclose()
gc_collect()

def test_aclose_throw(self):
async def gen():
return
yield

class MyException(Exception):
pass

g = gen()
with self.assertRaises(MyException):
gen.aclose().throw(MyException)


if __name__ == "__main__":
Expand Down
7 changes: 6 additions & 1 deletion Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,11 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na

retval = gen_throw((PyGenObject*)o->agt_gen, args, nargs);
if (o->agt_args) {
return async_gen_unwrap_value(o->agt_gen, retval);
retval = async_gen_unwrap_value(o->agt_gen, retval);
if (retval == NULL) {
o->agt_state = AWAITABLE_STATE_CLOSED;
}
return retval;
} else {
/* aclose() mode */
if (retval && _PyAsyncGenWrappedValue_CheckExact(retval)) {
Expand All @@ -2228,6 +2232,7 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na
*/
PyErr_Clear();
PyErr_SetNone(PyExc_StopIteration);
o->agt_state = AWAITABLE_STATE_CLOSED;
}
return retval;
}
Expand Down

0 comments on commit da89a69

Please sign in to comment.