@@ -51,6 +51,11 @@ interpreter.
5151 transparent for forward jumps but needs to be taken into account when
5252 reasoning about backward jumps.
5353
54+ .. versionchanged :: 3.13
55+ The output shows logical labels rather than instruction offsets
56+ for jump targets and exception handlers. The ``-O `` command line
57+ option and the ``show_offsets `` argument were added.
58+
5459Example: Given the function :func: `!myfunc `::
5560
5661 def myfunc(alist):
@@ -62,12 +67,12 @@ the following command can be used to display the disassembly of
6267.. doctest ::
6368
6469 >>> dis.dis(myfunc)
65- 2 0 RESUME 0
70+ 2 RESUME 0
6671 <BLANKLINE>
67- 3 2 LOAD_GLOBAL 1 (len + NULL)
68- 12 LOAD_FAST 0 (alist)
69- 14 CALL 1
70- 22 RETURN_VALUE
72+ 3 LOAD_GLOBAL 1 (len + NULL)
73+ LOAD_FAST 0 (alist)
74+ CALL 1
75+ RETURN_VALUE
7176
7277(The "2" is a line number).
7378
@@ -80,7 +85,7 @@ The :mod:`dis` module can be invoked as a script from the command line:
8085
8186.. code-block :: sh
8287
83- python -m dis [-h] [-C] [infile]
88+ python -m dis [-h] [-C] [-O] [ infile]
8489
8590 The following options are accepted:
8691
@@ -94,6 +99,10 @@ The following options are accepted:
9499
95100 Show inline caches.
96101
102+ .. cmdoption :: -O, --show-offsets
103+
104+ Show offsets of instructions.
105+
97106If :file: `infile ` is specified, its disassembled code will be written to stdout.
98107Otherwise, disassembly is performed on compiled source code recieved from stdin.
99108
@@ -107,7 +116,7 @@ The bytecode analysis API allows pieces of Python code to be wrapped in a
107116code.
108117
109118.. class :: Bytecode(x, *, first_line=None, current_offset=None,\
110- show_caches=False, adaptive=False)
119+ show_caches=False, adaptive=False, show_offsets=False )
111120
112121 Analyse the bytecode corresponding to a function, generator, asynchronous
113122 generator, coroutine, method, string of source code, or a code object (as
@@ -132,6 +141,9 @@ code.
132141 If *adaptive * is ``True ``, :meth: `.dis ` will display specialized bytecode
133142 that may be different from the original bytecode.
134143
144+ If *show_offsets * is ``True ``, :meth: `.dis ` will include instruction
145+ offsets in the output.
146+
135147 .. classmethod :: from_traceback(tb, *, show_caches=False)
136148
137149 Construct a :class: `Bytecode ` instance from the given traceback, setting
@@ -254,7 +266,8 @@ operation is being performed, so the intermediate analysis object isn't useful:
254266 Added the *show_caches * and *adaptive * parameters.
255267
256268
257- .. function :: distb(tb=None, *, file=None, show_caches=False, adaptive=False)
269+ .. function :: distb(tb=None, *, file=None, show_caches=False, adaptive=False,
270+ show_offset=False)
258271
259272 Disassemble the top-of-stack function of a traceback, using the last
260273 traceback if none was passed. The instruction causing the exception is
@@ -269,9 +282,12 @@ operation is being performed, so the intermediate analysis object isn't useful:
269282 .. versionchanged :: 3.11
270283 Added the *show_caches * and *adaptive * parameters.
271284
285+ .. versionchanged :: 3.13
286+ Added the *show_offsets * parameter.
272287
273288.. function :: disassemble(code, lasti=-1, *, file=None, show_caches=False, adaptive=False)
274- disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False)
289+ disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False,
290+ show_offsets=False)
275291
276292 Disassemble a code object, indicating the last instruction if *lasti * was
277293 provided. The output is divided in the following columns:
@@ -296,6 +312,8 @@ operation is being performed, so the intermediate analysis object isn't useful:
296312 .. versionchanged :: 3.11
297313 Added the *show_caches * and *adaptive * parameters.
298314
315+ .. versionchanged :: 3.13
316+ Added the *show_offsets * parameter.
299317
300318.. function :: get_instructions(x, *, first_line=None, show_caches=False, adaptive=False)
301319
0 commit comments