From 5b7952bafa9f433ca12170d3f14d62e4eb52d636 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Thu, 2 Jun 2022 17:15:00 +0800 Subject: [PATCH 1/6] Fix dis doc example output --- Doc/library/dis.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 8bc3721109b1ea..8647a7a8493f75 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -42,11 +42,11 @@ the following command can be used to display the disassembly of >>> dis.dis(myfunc) 1 0 RESUME 0 - 2 2 PUSH_NULL - 4 LOAD_GLOBAL 1 (NULL + len) - 6 LOAD_FAST 0 (alist) - 8 CALL 1 - 18 RETURN_VALUE + 2 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). @@ -115,7 +115,6 @@ Example:: ... print(instr.opname) ... RESUME - PUSH_NULL LOAD_GLOBAL LOAD_FAST CALL From 1de552f5ecf14c8a5776ab113421ee91229c69df Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Fri, 3 Jun 2022 12:06:09 +0800 Subject: [PATCH 2/6] Use doctest --- Doc/library/dis.rst | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 8647a7a8493f75..dea2891187e480 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,7 +43,9 @@ Example: Given the function :func:`myfunc`:: return len(alist) the following command can be used to display the disassembly of -:func:`myfunc`:: +:func:`myfunc`: + +.. doctest:: >>> dis.dis(myfunc) 1 0 RESUME 0 @@ -108,7 +116,9 @@ code. .. versionchanged:: 3.11 Added the ``show_caches`` parameter. -Example:: +Example: + +.. doctest:: >>> bytecode = dis.Bytecode(myfunc) >>> for instr in bytecode: From 052ccf5c9aa4c2f6fc90b237c12097cd667757c3 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Fri, 3 Jun 2022 12:08:43 +0800 Subject: [PATCH 3/6] PRECALL is gone in 3.12 --- Doc/library/dis.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index dea2891187e480..5aec7d453b783f 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -52,9 +52,8 @@ the following command can be used to display the disassembly of 2 2 LOAD_GLOBAL 1 (NULL + len) 14 LOAD_FAST 0 (alist) - 16 PRECALL 1 - 20 CALL 1 - 30 RETURN_VALUE + 16 CALL 1 + 26 RETURN_VALUE (The "2" is a line number). From b5deaa57e34a231a93e5a76f873192485d16ce8a Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Fri, 3 Jun 2022 13:54:41 +0800 Subject: [PATCH 4/6] Expect blankline --- Doc/library/dis.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 5aec7d453b783f..209a3faa76fdb4 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -49,7 +49,7 @@ the following command can be used to display the disassembly of >>> dis.dis(myfunc) 1 0 RESUME 0 - + 2 2 LOAD_GLOBAL 1 (NULL + len) 14 LOAD_FAST 0 (alist) 16 CALL 1 From 9be58f9e645d60850fe3b0282286352ffa232440 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Fri, 3 Jun 2022 14:49:38 +0800 Subject: [PATCH 5/6] indent blank line --- Doc/library/dis.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 209a3faa76fdb4..be8e3793770042 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -49,7 +49,7 @@ the following command can be used to display the disassembly of >>> dis.dis(myfunc) 1 0 RESUME 0 - + 2 2 LOAD_GLOBAL 1 (NULL + len) 14 LOAD_FAST 0 (alist) 16 CALL 1 From a3656bddd38fe16a540df726e0aaff677221ba65 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Fri, 3 Jun 2022 15:01:25 +0800 Subject: [PATCH 6/6] fix line numbers --- Doc/library/dis.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index be8e3793770042..313870ffa4de6a 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -48,9 +48,9 @@ the following command can be used to display the disassembly of .. doctest:: >>> dis.dis(myfunc) - 1 0 RESUME 0 + 2 0 RESUME 0 - 2 2 LOAD_GLOBAL 1 (NULL + len) + 3 2 LOAD_GLOBAL 1 (NULL + len) 14 LOAD_FAST 0 (alist) 16 CALL 1 26 RETURN_VALUE