diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-05-25 13:13:44 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-05-25 13:13:44 (GMT) |
commit | 1880d8b8231d0085700d5d3c03ee9b16c619720d (patch) | |
tree | 5ee56e8c0e04567dd7fb793a5c510007f623e3f3 /Doc | |
parent | 179bf213ea0432f2219c9b72ff4c4e18062fb588 (diff) | |
download | cpython-1880d8b8231d0085700d5d3c03ee9b16c619720d.zip cpython-1880d8b8231d0085700d5d3c03ee9b16c619720d.tar.gz cpython-1880d8b8231d0085700d5d3c03ee9b16c619720d.tar.bz2 |
add a SETUP_WITH opcode
It speeds up the with statement and correctly looks up the special
methods involved.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/dis.rst | 12 | ||||
-rw-r--r-- | Doc/reference/compound_stmts.rst | 4 |
2 files changed, 15 insertions, 1 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 6b7ed1e..9bd65dd 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -532,6 +532,18 @@ Miscellaneous opcodes. the names of the base classes, and TOS2 the class name. +.. opcode:: SETUP_WITH (delta) + + This opcode performs several operations before a with block starts. First, + it loads :meth:`~object.__exit__` from the context manager and pushes it onto + the stack for later use by :opcode:`WITH_CLEANUP`. Then, + :meth:`~object.__enter__` is called, and a finally block pointing to *delta* + is pushed. Finally, the result of calling the enter method is pushed onto + the stack. The next opcode will either ignore it (:opcode:`POP_TOP`), or + store it in (a) variable(s) (:opcode:`STORE_FAST`, :opcode:`STORE_NAME`, or + :opcode:`UNPACK_SEQUENCE`). + + .. opcode:: WITH_CLEANUP () Cleans up the stack when a :keyword:`with` statement block exits. On top of diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 3c716b2..afb7ebc 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -339,6 +339,8 @@ The execution of the :keyword:`with` statement proceeds as follows: #. The context expression is evaluated to obtain a context manager. +#. The context manager's :meth:`__exit__` is loaded for later use. + #. The context manager's :meth:`__enter__` method is invoked. #. If a target was included in the :keyword:`with` statement, the return value @@ -349,7 +351,7 @@ The execution of the :keyword:`with` statement proceeds as follows: The :keyword:`with` statement guarantees that if the :meth:`__enter__` method returns without an error, then :meth:`__exit__` will always be called. Thus, if an error occurs during the assignment to the target list, it will be treated the - same as an error occurring within the suite would be. See step 5 below. + same as an error occurring within the suite would be. See step 6 below. #. The suite is executed. |