Skip to content

Commit ce77e3b

Browse files
savannahostrowskimiss-islington
authored andcommitted
pythonGH-61082: Clarify nargs='*' positional default behavior (pythonGH-150989)
(cherry picked from commit bc37a22) Co-authored-by: Savannah Ostrowski <savannah@python.org>
1 parent fc9b11f commit ce77e3b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Doc/library/argparse.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,10 @@ is used when no command-line argument was present::
953953
>>> parser.parse_args([])
954954
Namespace(foo=42)
955955

956+
Because ``nargs='*'`` gathers any supplied values into a list, an absent
957+
positional argument yields an empty list (``[]``). Only a non-``None``
958+
*default* overrides this (so ``default=None`` still gives ``[]``).
959+
956960
For required_ arguments, the ``default`` value is ignored. For example, this
957961
applies to positional arguments with nargs_ values other than ``?`` or ``*``,
958962
or optional arguments marked as ``required=True``.

0 commit comments

Comments
 (0)