Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] gh-93433: Fix dis doc example output (GH-93434) #93460

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

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

.. testsetup::

import dis
def myfunc(alist):
return len(alist)

--------------

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

the following command can be used to display the disassembly of
:func:`myfunc`::
:func:`myfunc`:

>>> dis.dis(myfunc)
1 0 RESUME 0
.. doctest::

2 2 PUSH_NULL
4 LOAD_GLOBAL 1 (NULL + len)
6 LOAD_FAST 0 (alist)
8 PRECALL 1
10 CALL 1
12 RETURN_VALUE
>>> dis.dis(myfunc)
2 0 RESUME 0
<BLANKLINE>
3 2 LOAD_GLOBAL 1 (NULL + len)
14 LOAD_FAST 0 (alist)
16 PRECALL 1
20 CALL 1
30 RETURN_VALUE

(The "2" is a line number).

Expand Down Expand Up @@ -109,14 +116,15 @@ code.
.. versionchanged:: 3.11
Added the ``show_caches`` parameter.

Example::
Example:

.. doctest::

>>> bytecode = dis.Bytecode(myfunc)
>>> for instr in bytecode:
... print(instr.opname)
...
RESUME
PUSH_NULL
LOAD_GLOBAL
LOAD_FAST
PRECALL
Expand Down