Skip to content

Commit 3b39977

Browse files
serhiy-storchakamiss-islington
authored andcommitted
pythongh-85935: Explicitly document the case nargs=0 in argparse (pythonGH-125302)
(cherry picked from commit 07c2d15) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent b4c504d commit 3b39977

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎Doc/library/argparse.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ how the command-line arguments should be handled. The supplied actions are:
728728

729729
.. versionadded:: 3.8
730730

731+
Only actions that consume command-line arguments (e.g. ``'store'``,
732+
``'append'`` or ``'extend'``) can be used with positional arguments.
733+
731734
You may also specify an arbitrary action by passing an Action subclass or
732735
other object that implements the same interface. The ``BooleanOptionalAction``
733736
is available in ``argparse`` and adds support for boolean actions such as
@@ -855,6 +858,8 @@ See also :ref:`specifying-ambiguous-arguments`. The supported values are:
855858
If the ``nargs`` keyword argument is not provided, the number of arguments consumed
856859
is determined by the action_. Generally this means a single command-line argument
857860
will be consumed and a single item (not a list) will be produced.
861+
Actions that do not consume command-line arguments (e.g.
862+
``'store_const'``) set ``nargs=0``.
858863

859864

860865
.. _const:

0 commit comments

Comments
 (0)