Skip to content

Commit 74b91b1

Browse files
[3.11] gh-93433: Fix dis doc example output (GH-93434) (GH-93460)
(cherry picked from commit debf4c1)
1 parent 1d2b766 commit 74b91b1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

Doc/library/dis.rst

+19-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
**Source code:** :source:`Lib/dis.py`
88

9+
.. testsetup::
10+
11+
import dis
12+
def myfunc(alist):
13+
return len(alist)
14+
915
--------------
1016

1117
The :mod:`dis` module supports the analysis of CPython :term:`bytecode` by
@@ -37,17 +43,18 @@ Example: Given the function :func:`myfunc`::
3743
return len(alist)
3844

3945
the following command can be used to display the disassembly of
40-
:func:`myfunc`::
46+
:func:`myfunc`:
4147

42-
>>> dis.dis(myfunc)
43-
1 0 RESUME 0
48+
.. doctest::
4449

45-
2 2 PUSH_NULL
46-
4 LOAD_GLOBAL 1 (NULL + len)
47-
6 LOAD_FAST 0 (alist)
48-
8 PRECALL 1
49-
10 CALL 1
50-
12 RETURN_VALUE
50+
>>> dis.dis(myfunc)
51+
2 0 RESUME 0
52+
<BLANKLINE>
53+
3 2 LOAD_GLOBAL 1 (NULL + len)
54+
14 LOAD_FAST 0 (alist)
55+
16 PRECALL 1
56+
20 CALL 1
57+
30 RETURN_VALUE
5158

5259
(The "2" is a line number).
5360

@@ -109,14 +116,15 @@ code.
109116
.. versionchanged:: 3.11
110117
Added the ``show_caches`` parameter.
111118

112-
Example::
119+
Example:
120+
121+
.. doctest::
113122

114123
>>> bytecode = dis.Bytecode(myfunc)
115124
>>> for instr in bytecode:
116125
... print(instr.opname)
117126
...
118127
RESUME
119-
PUSH_NULL
120128
LOAD_GLOBAL
121129
LOAD_FAST
122130
PRECALL

0 commit comments

Comments
 (0)