Skip to content

Commit

Permalink
add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Nov 22, 2023
1 parent 823b0e1 commit 2219a96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 23 additions & 4 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ interpreter.
transparent for forward jumps but needs to be taken into account when
reasoning about backward jumps.

.. versionchanged:: 3.13
The output shows logical labels rather than instruction offsets
for jump targets and exception handlers. The ``-O`` command line
option and the ``show_offsets`` argument were added to add the
instruction offsets to the output as well.

Example: Given the function :func:`!myfunc`::

def myfunc(alist):
Expand Down Expand Up @@ -80,7 +86,7 @@ The :mod:`dis` module can be invoked as a script from the command line:

.. code-block:: sh
python -m dis [-h] [-C] [infile]
python -m dis [-h] [-C] [-O] [infile]
The following options are accepted:

Expand All @@ -94,6 +100,10 @@ The following options are accepted:

Show inline caches.

.. cmdoption:: -O, --show-offsets

Show offsets of instructions.

If :file:`infile` is specified, its disassembled code will be written to stdout.
Otherwise, disassembly is performed on compiled source code recieved from stdin.

Expand All @@ -107,7 +117,7 @@ The bytecode analysis API allows pieces of Python code to be wrapped in a
code.

.. class:: Bytecode(x, *, first_line=None, current_offset=None,\
show_caches=False, adaptive=False)
show_caches=False, adaptive=False, show_offsets=False)

Analyse the bytecode corresponding to a function, generator, asynchronous
generator, coroutine, method, string of source code, or a code object (as
Expand All @@ -132,6 +142,9 @@ code.
If *adaptive* is ``True``, :meth:`.dis` will display specialized bytecode
that may be different from the original bytecode.

If *show_offsets* is ``True``, :meth:`.dis` will include instruction
offsets in the output.

.. classmethod:: from_traceback(tb, *, show_caches=False)

Construct a :class:`Bytecode` instance from the given traceback, setting
Expand Down Expand Up @@ -254,7 +267,8 @@ operation is being performed, so the intermediate analysis object isn't useful:
Added the *show_caches* and *adaptive* parameters.


.. function:: distb(tb=None, *, file=None, show_caches=False, adaptive=False)
.. function:: distb(tb=None, *, file=None, show_caches=False, adaptive=False,
show_offset=False)

Disassemble the top-of-stack function of a traceback, using the last
traceback if none was passed. The instruction causing the exception is
Expand All @@ -269,9 +283,12 @@ operation is being performed, so the intermediate analysis object isn't useful:
.. versionchanged:: 3.11
Added the *show_caches* and *adaptive* parameters.

.. versionchanged:: 3.13
Added the *show_offsets* parameter.

.. function:: disassemble(code, lasti=-1, *, file=None, show_caches=False, adaptive=False)
disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False)
disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False,
show_offsets=False)
Disassemble a code object, indicating the last instruction if *lasti* was
provided. The output is divided in the following columns:
Expand All @@ -296,6 +313,8 @@ operation is being performed, so the intermediate analysis object isn't useful:
.. versionchanged:: 3.11
Added the *show_caches* and *adaptive* parameters.

.. versionchanged:: 3.13
Added the *show_offsets* parameter.

.. function:: get_instructions(x, *, first_line=None, show_caches=False, adaptive=False)

Expand Down
2 changes: 2 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ dis

* Change the output of :mod:`dis` module functions to show logical
labels for jump targets and exception handlers, rather than offsets.
The offsets can be added with the new ``-O`` command line option or
the ``show_offsets`` parameter.
(Contributed by Irit Katriel in :gh:`112137`.)

dbm
Expand Down

0 comments on commit 2219a96

Please sign in to comment.