Skip to content

Commit 0d416d3

Browse files
pythongh-85935: Excplicitly document the case nargs=0 in argparse
1 parent 04b2a8f commit 0d416d3

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

961961
.. versionadded:: 3.8
962962

963+
Only actions that consume command-line arguments (such as ``'store'``,
964+
``'append'`` or ``'extend'``) can be used with positional arguments.
965+
963966
You may also specify an arbitrary action by passing an Action subclass or
964967
other object that implements the same interface. The ``BooleanOptionalAction``
965968
is available in ``argparse`` and adds support for boolean actions such as
@@ -1087,6 +1090,8 @@ See also :ref:`specifying-ambiguous-arguments`. The supported values are:
10871090
If the ``nargs`` keyword argument is not provided, the number of arguments consumed
10881091
is determined by the action_. Generally this means a single command-line argument
10891092
will be consumed and a single item (not a list) will be produced.
1093+
Actions that do not consume command-line arguments (such as
1094+
``'store_const'``) set ``nargs=0``.
10901095

10911096

10921097
.. _const:

0 commit comments

Comments
 (0)