bpo-39386: Prevent double awaiting of async iterator (GH-18081)
(cherry picked from commit a96e06db77dcbd3433d39761ddb4615d7d96284a)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 5643553..72aa872 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -1533,7 +1533,9 @@
PyObject *result;
if (o->ags_state == AWAITABLE_STATE_CLOSED) {
- PyErr_SetNone(PyExc_StopIteration);
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "cannot reuse already awaited __anext__()/asend()");
return NULL;
}
@@ -1576,7 +1578,9 @@
PyObject *result;
if (o->ags_state == AWAITABLE_STATE_CLOSED) {
- PyErr_SetNone(PyExc_StopIteration);
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "cannot reuse already awaited __anext__()/asend()");
return NULL;
}
@@ -1810,7 +1814,9 @@
if (f == NULL || f->f_stacktop == NULL ||
o->agt_state == AWAITABLE_STATE_CLOSED) {
- PyErr_SetNone(PyExc_StopIteration);
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "cannot reuse already awaited aclose()/athrow()");
return NULL;
}
@@ -1932,7 +1938,9 @@
PyObject *retval;
if (o->agt_state == AWAITABLE_STATE_CLOSED) {
- PyErr_SetNone(PyExc_StopIteration);
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "cannot reuse already awaited aclose()/athrow()");
return NULL;
}