Skip to content

[3.11] gh-108826: Document dis module CLI and rename _test function to main (#108827) #110689

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

Merged
merged 1 commit into from
Oct 11, 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: 2 additions & 0 deletions Doc/library/asyncio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Additionally, there are **low-level** APIs for
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
with async/await syntax.

.. _asyncio-cli:

You can experiment with an ``asyncio`` concurrent context in the REPL:

.. code-block:: pycon
Expand Down
55 changes: 55 additions & 0 deletions Doc/library/cmdline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
++++++++++++++++++++++++++++++++++++
Modules command-line interface (CLI)
++++++++++++++++++++++++++++++++++++

The following modules have a command-line interface.

* :ref:`ast <ast-cli>`
* :ref:`asyncio <asyncio-cli>`
* :mod:`base64`
* :ref:`calendar <calendar-cli>`
* :mod:`code`
* :ref:`compileall <compileall-cli>`
* :mod:`cProfile`: see :ref:`profile <profile-cli>`
* :ref:`difflib <difflib-interface>`
* :ref:`dis <dis-cli>`
* :mod:`doctest`
* :mod:`!encodings.rot_13`
* :mod:`ensurepip`
* :mod:`filecmp`
* :mod:`fileinput`
* :mod:`ftplib`
* :ref:`gzip <gzip-cli>`
* :ref:`http.server <http-server-cli>`
* :mod:`!idlelib`
* :ref:`inspect <inspect-module-cli>`
* :ref:`json.tool <json-commandline>`
* :mod:`mimetypes`
* :mod:`pdb`
* :mod:`pickle`
* :ref:`pickletools <pickletools-cli>`
* :mod:`platform`
* :mod:`poplib`
* :ref:`profile <profile-cli>`
* :mod:`pstats`
* :ref:`py_compile <py_compile-cli>`
* :mod:`pyclbr`
* :mod:`pydoc`
* :mod:`quopri`
* :mod:`runpy`
* :ref:`site <site-commandline>`
* :ref:`sysconfig <sysconfig-cli>`
* :mod:`tabnanny`
* :ref:`tarfile <tarfile-commandline>`
* :mod:`!this`
* :ref:`timeit <timeit-command-line-interface>`
* :ref:`tokenize <tokenize-cli>`
* :ref:`trace <trace-cli>`
* :mod:`turtledemo`
* :ref:`unittest <unittest-command-line-interface>`
* :mod:`venv`
* :mod:`webbrowser`
* :ref:`zipapp <zipapp-command-line-interface>`
* :ref:`zipfile <zipfile-commandline>`

See also the :ref:`Python command-line interface <using-on-general>`.
2 changes: 2 additions & 0 deletions Doc/library/compileall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ have write permission to the library directories.

.. include:: ../includes/wasm-notavail.rst

.. _compileall-cli:

Command-line use
----------------

Expand Down
26 changes: 26 additions & 0 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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
2 changes: 2 additions & 0 deletions Doc/library/gzip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ Example of how to GZIP compress a binary string::

.. program:: gzip

.. _gzip-cli:

Command Line Interface
----------------------

Expand Down
1 change: 1 addition & 0 deletions Doc/library/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ the `Python Package Index <https://pypi.org>`_.
language.rst
windows.rst
unix.rst
cmdline.rst
superseded.rst
security_warnings.rst
2 changes: 2 additions & 0 deletions Doc/library/pickletools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ are useful for Python core developers who are working on the :mod:`pickle`;
ordinary users of the :mod:`pickle` module probably won't find the
:mod:`pickletools` module relevant.

.. _pickletools-cli:

Command line usage
------------------

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/profile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ results to a file by specifying a filename to the :func:`run` function::
The :class:`pstats.Stats` class reads profile results from a file and formats
them in various ways.

.. _profile-cli:

The files :mod:`cProfile` and :mod:`profile` can also be invoked as a script to
profile another script. For example::

Expand Down
1 change: 1 addition & 0 deletions Doc/library/py_compile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ byte-code cache files in the directory containing the source code.
This option is useful when the ``.pycs`` are kept up to date by some
system external to Python like a build system.

.. _py_compile-cli:

Command-Line Interface
----------------------
Expand Down
1 change: 1 addition & 0 deletions Doc/library/sysconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ Other functions

Return the path of :file:`Makefile`.

.. _sysconfig-cli:

Using :mod:`sysconfig` as a script
----------------------------------
Expand Down
5 changes: 2 additions & 3 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,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 @@ -772,4 +771,4 @@ def _test():
dis(code)

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.