[Python-checkins] [3.11] gh-93433: Fix dis doc example output (GH-93434) (GH-93460)
Fidget-Spinner
webhook-mailer at python.org
Fri Jun 3 09:27:00 EDT 2022
https://github.com/python/cpython/commit/74b91b1763b311cb417b32f9b271ae5a4590a13c
commit: 74b91b1763b311cb417b32f9b271ae5a4590a13c
branch: 3.11
author: Ken Jin <kenjin4096 at gmail.com>
committer: Fidget-Spinner <kenjin4096 at gmail.com>
date: 2022-06-03T21:26:43+08:00
summary:
[3.11] gh-93433: Fix dis doc example output (GH-93434) (GH-93460)
(cherry picked from commit debf4c1ec5f0bae44d50f889b8a7dc0c3ea1fc9d)
files:
M Doc/library/dis.rst
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 08e6c736d3e3c..27a2f6bf79524 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -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
@@ -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).
@@ -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
More information about the Python-checkins
mailing list