summaryrefslogtreecommitdiffstats
path: root/Doc/library/dis.rst
diff options
context:
space:
mode:
authorKen Jin <kenjin4096@gmail.com>2022-06-03 10:02:58 (GMT)
committerGitHub <noreply@github.com>2022-06-03 10:02:58 (GMT)
commitdebf4c1ec5f0bae44d50f889b8a7dc0c3ea1fc9d (patch)
tree4e21c93177f3255d2b56d2b481ede8daf8c36c39 /Doc/library/dis.rst
parentb9509ba7a9c668b984dab876c7926fe1dc5aa0ba (diff)
downloadcpython-debf4c1ec5f0bae44d50f889b8a7dc0c3ea1fc9d.zip
cpython-debf4c1ec5f0bae44d50f889b8a7dc0c3ea1fc9d.tar.gz
cpython-debf4c1ec5f0bae44d50f889b8a7dc0c3ea1fc9d.tar.bz2
gh-93433: Fix dis doc example output (GH-93434)
Diffstat (limited to 'Doc/library/dis.rst')
-rw-r--r--Doc/library/dis.rst28
1 files changed, 18 insertions, 10 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 8bc3721..313870f 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -6,6 +6,12 @@
**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
@@ -37,16 +43,17 @@ Example: Given the function :func:`myfunc`::
return len(alist)
the following command can be used to display the disassembly of
-:func:`myfunc`::
+:func:`myfunc`:
- >>> dis.dis(myfunc)
- 1 0 RESUME 0
+.. doctest::
- 2 2 PUSH_NULL
- 4 LOAD_GLOBAL 1 (NULL + len)
- 6 LOAD_FAST 0 (alist)
- 8 CALL 1
- 18 RETURN_VALUE
+ >>> dis.dis(myfunc)
+ 2 0 RESUME 0
+ <BLANKLINE>
+ 3 2 LOAD_GLOBAL 1 (NULL + len)
+ 14 LOAD_FAST 0 (alist)
+ 16 CALL 1
+ 26 RETURN_VALUE
(The "2" is a line number).
@@ -108,14 +115,15 @@ code.
.. versionchanged:: 3.11
Added the ``show_caches`` parameter.
-Example::
+Example:
+
+.. doctest::
>>> bytecode = dis.Bytecode(myfunc)
>>> for instr in bytecode:
... print(instr.opname)
...
RESUME
- PUSH_NULL
LOAD_GLOBAL
LOAD_FAST
CALL