]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-85935: Explicitly document the case nargs=0 in argparse (GH-125302)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 12 Oct 2024 11:53:00 +0000 (14:53 +0300)
committerGitHub <noreply@github.com>
Sat, 12 Oct 2024 11:53:00 +0000 (11:53 +0000)
Doc/library/argparse.rst

index 19f832051a9ee82bda39738c95b47739d72b795b..d58c75eef3e739d415c9b7fbea4340537afa466a 100644 (file)
@@ -751,6 +751,9 @@ how the command-line arguments should be handled. The supplied actions are:
 
   .. versionadded:: 3.8
 
+Only actions that consume command-line arguments (e.g. ``'store'``,
+``'append'`` or ``'extend'``) can be used with positional arguments.
+
 You may also specify an arbitrary action by passing an Action subclass or
 other object that implements the same interface. The ``BooleanOptionalAction``
 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:
 If the ``nargs`` keyword argument is not provided, the number of arguments consumed
 is determined by the action_.  Generally this means a single command-line argument
 will be consumed and a single item (not a list) will be produced.
+Actions that do not consume command-line arguments (e.g.
+``'store_const'``) set ``nargs=0``.
 
 
 .. _const: