From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 9 Jun 2026 15:44:07 +0000 (+0200) Subject: [3.13] GH-61082: Clarify nargs='*' positional default behavior (GH-150989) (#151170) X-Git-Tag: v3.13.14~17 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=558764600ffa7406affc617b09b14d4937f259c4;p=thirdparty%2FPython%2Fcpython.git [3.13] GH-61082: Clarify nargs='*' positional default behavior (GH-150989) (#151170) GH-61082: Clarify nargs='*' positional default behavior (GH-150989) (cherry picked from commit bc37a227b2f481d0f260f9beae5229e8d432a0cc) Co-authored-by: Savannah Ostrowski --- diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 89b9faf9f60d..fa5b92ed81b8 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -953,6 +953,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``.