]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Don't raise an exception on normal return from generator. (GH-19473)
authorMark Shannon <mark@hotpy.org>
Thu, 4 Jun 2020 12:23:35 +0000 (13:23 +0100)
committerGitHub <noreply@github.com>
Thu, 4 Jun 2020 12:23:35 +0000 (13:23 +0100)
Misc/NEWS.d/next/Core and Builtins/2020-04-11-13-07-49.bpo-4022.Ctpn_F.rst [new file with mode: 0644]
Objects/genobject.c

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 (file)
index 0000000..a13a8e8
--- /dev/null
@@ -0,0 +1 @@
+Improve performance of generators by not raising internal StopIteration.
index 09efbab69a7d3af4eed62fa9045b8a6892f55670..1393f42533a59f0e66b3597e5846c1a6ac2a9eaf 100644 (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);
             }
         }