Skip to content

Commit 50a48da

Browse files
authored
Don't raise an exception on normal return from generator. (GH-19473)
1 parent 6e23a9c commit 50a48da

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve performance of generators by not raising internal StopIteration.

Objects/genobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
231231
if (PyAsyncGen_CheckExact(gen)) {
232232
PyErr_SetNone(PyExc_StopAsyncIteration);
233233
}
234-
else {
234+
else if (arg) {
235+
/* Set exception if not called by gen_iternext() */
235236
PyErr_SetNone(PyExc_StopIteration);
236237
}
237238
}

0 commit comments

Comments
 (0)