mirror of
https://github.com/python/cpython.git
synced 2026-07-25 11:22:45 -04:00
[3.15] GH-61082: Clarify nargs='*' positional default behavior (GH-150989) (#151168)
GH-61082: Clarify nargs='*' positional default behavior (GH-150989)
(cherry picked from commit bc37a227b2)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
This commit is contained in:
committed by
GitHub
parent
804be0a223
commit
fda4f22d60
@@ -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``.
|
||||
|
||||
Reference in New Issue
Block a user