diff options
author | Mark Shannon <mark@hotpy.org> | 2020-06-04 13:23:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-04 13:23:35 +0100 |
commit | 50a48dad5579d67d7cae350f6ad5ae5c33f56abb (patch) | |
tree | caba0849e1ea3e65a0f6c3cd933d5b4a6bd21138 | |
parent | 6e23a9c82b7fd2366003b9191cd93a9683b9d80c (diff) | |
download | cpython-git-50a48dad5579d67d7cae350f6ad5ae5c33f56abb.tar.gz |
Don't raise an exception on normal return from generator. (GH-19473)
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst | 1 | ||||
-rw-r--r-- | Objects/genobject.c | 3 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst new file mode 100644 index 0000000000..a13a8e8822 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst @@ -0,0 +1 @@ +Improve performance of generators by not raising internal StopIteration. diff --git a/Objects/genobject.c b/Objects/genobject.c index 09efbab69a..1393f42533 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -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); } } |