Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e8814fb

Browse files
committed
As per python-dev discussion with Eli, properly document and publish dis.show_code
1 parent c02adca commit e8814fb

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

Doc/library/dis.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ the following command can be used to get the disassembly of :func:`myfunc`::
3636
The :mod:`dis` module defines the following functions and constants:
3737

3838

39-
.. function:: code_info(x=None)
39+
.. function:: code_info(x)
4040

4141
Return a formatted multi-line string with detailed code object information
4242
for the supplied function, method, source code string or code object.
@@ -48,6 +48,16 @@ The :mod:`dis` module defines the following functions and constants:
4848
.. versionadded:: 3.2
4949

5050

51+
.. function:: show_code(x)
52+
53+
Print detailed code object information for the supplied function, method,
54+
source code string or code object to stdout.
55+
56+
This is a convenient shorthand for ``print(code_info(x))``, intended for
57+
interactive exploration at the interpreter prompt.
58+
59+
.. versionadded:: 3.2
60+
5161
.. function:: dis(x=None)
5262

5363
Disassemble the *x* object. *x* can denote either a module, a class, a

Lib/dis.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from opcode import __all__ as _opcodes_all
88

99
__all__ = ["code_info", "dis", "disassemble", "distb", "disco",
10-
"findlinestarts", "findlabels"] + _opcodes_all
10+
"findlinestarts", "findlabels", "show_code"] + _opcodes_all
1111
del _opcodes_all
1212

1313
_have_code = (types.MethodType, types.FunctionType, types.CodeType, type)
@@ -140,12 +140,8 @@ def _format_code_info(co):
140140
lines.append("%4d: %s" % i_n)
141141
return "\n".join(lines)
142142

143-
# show_code is deliberately undocumented and left out of __all__,
144-
# since it doesn't offer any real benefit over code_info() above
145-
# It is only retained because it already existed and was not
146-
# marked as private in previous versions of Python
147143
def show_code(co):
148-
"""Show details about a code object."""
144+
"""Print details of methods, functions, or code to stdout."""
149145
print(code_info(co))
150146

151147
def disassemble(co, lasti=-1):

0 commit comments

Comments
 (0)