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

gh-108826: Document dis module CLI and rename _test function to main #108827

Merged
merged 16 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Doc/library/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following modules have a command-line interface.
* :ref:`compileall <compileall-cli>`
* :mod:`cProfile`: see :ref:`profile <profile-cli>`
* :ref:`difflib <difflib-interface>`
* :mod:`dis`
* :ref:`dis <dis-cli>`
* :mod:`doctest`
* :mod:`!encodings.rot_13`
* :mod:`ensurepip`
Expand Down
26 changes: 26 additions & 0 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ the following command can be used to display the disassembly of

(The "2" is a line number).

.. _dis-cli:

Command-line interface
----------------------

The :mod:`dis` module can be invoked as a script from the command line:

.. code-block:: sh

python -m dis [-h] [-C] [infile]

The following options are accepted:

.. program:: dis

.. cmdoption:: -h, --help

Display usage and exit.

.. cmdoption:: -C, --show-caches

Show inline caches.

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

Bytecode analysis
-----------------

Expand Down
5 changes: 2 additions & 3 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,7 @@ def dis(self):
return output.getvalue()


def _test():
"""Simple test program to disassemble a file."""
def main():
import argparse

parser = argparse.ArgumentParser()
Expand All @@ -911,4 +910,4 @@ def _test():
dis(code, show_caches=args.show_caches)

if __name__ == "__main__":
_test()
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`dis` module command-line interface is now mentioned in documentation.