summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-10-27 10:55:03 (GMT)
committerGitHub <noreply@github.com>2022-10-27 10:55:03 (GMT)
commit22863df7ca5f9cd01a40ab3dce3d067ec5666081 (patch)
tree73c460d80f41b45a331b7d886defe39127e12472 /Doc/library
parente60892f9db1316dbabf7a652d7648e4f968b745d (diff)
downloadcpython-22863df7ca5f9cd01a40ab3dce3d067ec5666081.zip
cpython-22863df7ca5f9cd01a40ab3dce3d067ec5666081.tar.gz
cpython-22863df7ca5f9cd01a40ab3dce3d067ec5666081.tar.bz2
GH-96793: Change `FOR_ITER` to not pop the iterator on exhaustion. (GH-96801)
Change FOR_ITER to have the same stack effect regardless of whether it branches or not. Performance is unchanged as FOR_ITER (and specialized forms jump over the cleanup code).
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/dis.rst13
1 files changed, 12 insertions, 1 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index c6b4303..1eaa9f3 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -413,6 +413,15 @@ The Python compiler currently generates the following bytecode instructions.
Removes the top-of-stack (TOS) item.
+.. opcode:: END_FOR
+
+ Removes the top two values from the stack.
+ Equivalent to POP_TOP; POP_TOP.
+ Used to clean up at the end of loops, hence the name.
+
+ .. versionadded:: 3.12
+
+
.. opcode:: COPY (i)
Push the *i*-th item to the top of the stack. The item is not removed from its
@@ -1088,9 +1097,11 @@ iterations of the loop.
TOS is an :term:`iterator`. Call its :meth:`~iterator.__next__` method. If
this yields a new value, push it on the stack (leaving the iterator below
- it). If the iterator indicates it is exhausted, TOS is popped, and the byte
+ it). If the iterator indicates it is exhausted then the byte
code counter is incremented by *delta*.
+ .. versionchanged:: 3.12
+ Up until 3.11 the iterator was popped when it was exhausted.
.. opcode:: LOAD_GLOBAL (namei)