File tree 1 file changed +18
-10
lines changed
1 file changed +18
-10
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,16 +43,17 @@ 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 CALL 1
49
- 18 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 CALL 1
56
+ 26 RETURN_VALUE
50
57
51
58
(The "2" is a line number).
52
59
@@ -108,14 +115,15 @@ code.
108
115
.. versionchanged :: 3.11
109
116
Added the ``show_caches `` parameter.
110
117
111
- Example::
118
+ Example:
119
+
120
+ .. doctest ::
112
121
113
122
>>> bytecode = dis.Bytecode(myfunc)
114
123
>>> for instr in bytecode:
115
124
... print (instr.opname)
116
125
...
117
126
RESUME
118
- PUSH_NULL
119
127
LOAD_GLOBAL
120
128
LOAD_FAST
121
129
CALL
You can’t perform that action at this time.
0 commit comments