GH-61082: Clarify nargs='*' positional default behavior (#150989)

This commit is contained in:
Savannah Ostrowski 2026-06-09 08:37:24 -07:00 committed by GitHub
parent 528550e0e7
commit bc37a227b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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``.