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

bpo-13850: Add summary tables for argparse add_argument options #12070

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 41 additions & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,48 @@ The :mod:`argparse` module makes it easy to write user-friendly command-line
interfaces. The program defines what arguments it requires, and :mod:`argparse`
will figure out how to parse those out of :data:`sys.argv`. The :mod:`argparse`
module also automatically generates help and usage messages and issues errors
when users give the program invalid arguments.
when users give the program invalid arguments. See the `Quick Reference`_ for a
summary table of applicable parameters for each action_ in
:meth:`~ArgumentParser.add_argument`.

Quick Reference
---------------

The table below provides a summary of applicable parameters (columns) of the
add_argument() method for each functional action_ (rows).

+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
| |``nargs``|``const`` |``default``|``type``|``choices``|``required``|``help``|``metavar``|``dest``|``version``|
+=================+=========+================+===========+========+===========+============+========+===========+========+===========+
|``store`` |x |if ``nargs='?'``|x |x |x |x |x |x |x | |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
|``store_const`` | |x |x | | |x |x |x |x | |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
|``store_true`` | |x |x | | |x |x |x |x | |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
|``store_false`` | |x |x | | |x |x |x |x | |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
|``append`` |x |if ``nargs='?'``|x |x |x |x |x |x |x | |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
|``append_const`` | |x |x | | |x |x |x |x | |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
|``count`` | | | | | | |x |x |x | |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+
|``version`` | | | | | | | | | |x |
+-----------------+---------+----------------+-----------+--------+-----------+------------+--------+-----------+--------+-----------+

.. note::

* ``default`` can be set to ``argparse.SUPPRESS`` to prevent the
attribute from being added

* ``nargs='?'`` will use ``default`` if the argument is not
specified, but ``const`` if the argument is specified with no
value provided

* list-type ``nargs`` (an ``int``, ``'*'`` or ``'+'``) causes a
list to be used: ``store`` becomes a list and ``append`` becomes
a list of lists

Example
-------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add asummary of applicable parameters of the
:meth:`~ArgumentParser.add_argument`. Original patch by Xavier Morel,
updated by Tina Zhang. Contributed by Stéphane Wirtel.