Skip to content

Commit 095c414

Browse files
pythongh-85935: Excplicitly document the case nargs=0 in argparse
1 parent 01fc3b3 commit 095c414

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
@@ -731,6 +731,9 @@ how the command-line arguments should be handled. The supplied actions are:
731731

732732
.. versionadded:: 3.8
733733

734+
Only actions that consume command-line arguments (such as ``'store'``,
735+
``'append'`` or ``'extend'``) can be used with positional arguments.
736+
734737
You may also specify an arbitrary action by passing an Action subclass or
735738
other object that implements the same interface. The ``BooleanOptionalAction``
736739
is available in ``argparse`` and adds support for boolean actions such as
@@ -858,6 +861,8 @@ See also :ref:`specifying-ambiguous-arguments`. The supported values are:
858861
If the ``nargs`` keyword argument is not provided, the number of arguments consumed
859862
is determined by the action_. Generally this means a single command-line argument
860863
will be consumed and a single item (not a list) will be produced.
864+
Actions that do not consume command-line arguments (such as
865+
``'store_const'``) set ``nargs=0``.
861866

862867

863868
.. _const:

0 commit comments

Comments
 (0)