Skip to content

Commit 07c2d15

Browse files
gh-85935: Explicitly document the case nargs=0 in argparse (GH-125302)
1 parent a6c0c64 commit 07c2d15

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Doc/library/argparse.rst

+5
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ how the command-line arguments should be handled. The supplied actions are:
751751

752752
.. versionadded:: 3.8
753753

754+
Only actions that consume command-line arguments (e.g. ``'store'``,
755+
``'append'`` or ``'extend'``) can be used with positional arguments.
756+
754757
You may also specify an arbitrary action by passing an Action subclass or
755758
other object that implements the same interface. The ``BooleanOptionalAction``
756759
is available in ``argparse`` and adds support for boolean actions such as
@@ -878,6 +881,8 @@ See also :ref:`specifying-ambiguous-arguments`. The supported values are:
878881
If the ``nargs`` keyword argument is not provided, the number of arguments consumed
879882
is determined by the action_. Generally this means a single command-line argument
880883
will be consumed and a single item (not a list) will be produced.
884+
Actions that do not consume command-line arguments (e.g.
885+
``'store_const'``) set ``nargs=0``.
881886

882887

883888
.. _const:

0 commit comments

Comments
 (0)