mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
[3.11] gh-93433: Fix dis doc example output (GH-93434) (GH-93460)
(cherry picked from commit debf4c1ec5
)
This commit is contained in:
parent
1d2b766100
commit
74b91b1763
1 changed files with 19 additions and 11 deletions
|
@ -6,6 +6,12 @@
|
||||||
|
|
||||||
**Source code:** :source:`Lib/dis.py`
|
**Source code:** :source:`Lib/dis.py`
|
||||||
|
|
||||||
|
.. testsetup::
|
||||||
|
|
||||||
|
import dis
|
||||||
|
def myfunc(alist):
|
||||||
|
return len(alist)
|
||||||
|
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
The :mod:`dis` module supports the analysis of CPython :term:`bytecode` by
|
The :mod:`dis` module supports the analysis of CPython :term:`bytecode` by
|
||||||
|
@ -37,17 +43,18 @@ Example: Given the function :func:`myfunc`::
|
||||||
return len(alist)
|
return len(alist)
|
||||||
|
|
||||||
the following command can be used to display the disassembly of
|
the following command can be used to display the disassembly of
|
||||||
:func:`myfunc`::
|
:func:`myfunc`:
|
||||||
|
|
||||||
|
.. doctest::
|
||||||
|
|
||||||
>>> dis.dis(myfunc)
|
>>> dis.dis(myfunc)
|
||||||
1 0 RESUME 0
|
2 0 RESUME 0
|
||||||
|
<BLANKLINE>
|
||||||
2 2 PUSH_NULL
|
3 2 LOAD_GLOBAL 1 (NULL + len)
|
||||||
4 LOAD_GLOBAL 1 (NULL + len)
|
14 LOAD_FAST 0 (alist)
|
||||||
6 LOAD_FAST 0 (alist)
|
16 PRECALL 1
|
||||||
8 PRECALL 1
|
20 CALL 1
|
||||||
10 CALL 1
|
30 RETURN_VALUE
|
||||||
12 RETURN_VALUE
|
|
||||||
|
|
||||||
(The "2" is a line number).
|
(The "2" is a line number).
|
||||||
|
|
||||||
|
@ -109,14 +116,15 @@ code.
|
||||||
.. versionchanged:: 3.11
|
.. versionchanged:: 3.11
|
||||||
Added the ``show_caches`` parameter.
|
Added the ``show_caches`` parameter.
|
||||||
|
|
||||||
Example::
|
Example:
|
||||||
|
|
||||||
|
.. doctest::
|
||||||
|
|
||||||
>>> bytecode = dis.Bytecode(myfunc)
|
>>> bytecode = dis.Bytecode(myfunc)
|
||||||
>>> for instr in bytecode:
|
>>> for instr in bytecode:
|
||||||
... print(instr.opname)
|
... print(instr.opname)
|
||||||
...
|
...
|
||||||
RESUME
|
RESUME
|
||||||
PUSH_NULL
|
|
||||||
LOAD_GLOBAL
|
LOAD_GLOBAL
|
||||||
LOAD_FAST
|
LOAD_FAST
|
||||||
PRECALL
|
PRECALL
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue