Skip to content

Commit 31c2e9e

Browse files
committed
clear StopAsyncIteration before calling _PyGen_SetStopIterationValue
1 parent 3a570c6 commit 31c2e9e

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

Objects/genobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ gen_iternext(PyObject *self)
633633
int
634634
_PyGen_SetStopIterationValue(PyObject *value)
635635
{
636+
assert(!PyErr_Occurred());
636637
PyObject *e;
637638

638639
if (value == NULL ||

Objects/iterobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ anextawaitable_iternext(anextawaitableobject *obj)
384384
return result;
385385
}
386386
if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration)) {
387+
PyErr_Clear();
387388
_PyGen_SetStopIterationValue(obj->default_value);
388389
}
389390
return NULL;
@@ -407,6 +408,7 @@ anextawaitable_proxy(anextawaitableobject *obj, char *meth, PyObject *arg) {
407408
* exception we replace it with a `StopIteration(default)`, as if
408409
* it was the return value of `__anext__()` coroutine.
409410
*/
411+
PyErr_Clear();
410412
_PyGen_SetStopIterationValue(obj->default_value);
411413
}
412414
return NULL;

0 commit comments

Comments
 (0)