]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-61082: Clarify nargs='*' positional default behavior (#150989)
authorSavannah Ostrowski <savannah@python.org>
Tue, 9 Jun 2026 15:37:24 +0000 (08:37 -0700)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2026 15:37:24 +0000 (15:37 +0000)
Doc/library/argparse.rst

index 622f844a4a0b825d4ccdb707e5a84f77fca4b039..4c588d447a9a7cf030f87a54733c0451dacb9e57 100644 (file)
@@ -1051,6 +1051,10 @@ is used when no command-line argument was present::
    >>> parser.parse_args([])
    Namespace(foo=42)
 
+Because ``nargs='*'`` gathers any supplied values into a list, an absent
+positional argument yields an empty list (``[]``). Only a non-``None``
+*default* overrides this (so ``default=None`` still gives ``[]``).
+
 For required_ arguments, the ``default`` value is ignored. For example, this
 applies to positional arguments with nargs_ values other than ``?`` or ``*``,
 or optional arguments marked as ``required=True``.