Don't raise an exception on normal return from generator. (GH-19473)

This commit is contained in:
Mark Shannon 2020-06-04 13:23:35 +01:00 committed by GitHub
parent 6e23a9c82b
commit 50a48dad55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -0,0 +1 @@
Improve performance of generators by not raising internal StopIteration.

View File

@ -231,7 +231,8 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
if (PyAsyncGen_CheckExact(gen)) {
PyErr_SetNone(PyExc_StopAsyncIteration);
}
else {
else if (arg) {
/* Set exception if not called by gen_iternext() */
PyErr_SetNone(PyExc_StopIteration);
}
}