File tree 1 file changed +19
-11
lines changed
1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change 6
6
7
7
**Source code: ** :source: `Lib/dis.py `
8
8
9
+ .. testsetup ::
10
+
11
+ import dis
12
+ def myfunc(alist):
13
+ return len(alist)
14
+
9
15
--------------
10
16
11
17
The :mod: `dis ` module supports the analysis of CPython :term: `bytecode ` by
@@ -37,17 +43,18 @@ Example: Given the function :func:`myfunc`::
37
43
return len(alist)
38
44
39
45
the following command can be used to display the disassembly of
40
- :func: `myfunc `::
46
+ :func: `myfunc `:
41
47
42
- >>> dis.dis(myfunc)
43
- 1 0 RESUME 0
48
+ .. doctest ::
44
49
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
51
58
52
59
(The "2" is a line number).
53
60
@@ -109,14 +116,15 @@ code.
109
116
.. versionchanged :: 3.11
110
117
Added the ``show_caches `` parameter.
111
118
112
- Example::
119
+ Example:
120
+
121
+ .. doctest ::
113
122
114
123
>>> bytecode = dis.Bytecode(myfunc)
115
124
>>> for instr in bytecode:
116
125
... print (instr.opname)
117
126
...
118
127
RESUME
119
- PUSH_NULL
120
128
LOAD_GLOBAL
121
129
LOAD_FAST
122
130
PRECALL
You can’t perform that action at this time.
0 commit comments