From 1f9516a730b7a079724389d1a3cd33e7e5c7ee64 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 5 Jun 2026 14:46:33 -0700 Subject: [PATCH 1/2] Add clarification on nargs='*' positional default behavior --- Doc/library/argparse.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index db5fae2006678a..dac09e5a0df6a3 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1052,6 +1052,10 @@ is used when no command-line argument was present:: >>> parser.parse_args([]) Namespace(foo=42) +Because ``nargs='*'`` collects matched values into a list, an absent positional +argument yields an empty list (``[]``); a default of ``None`` is replaced by +``[]``, although any other default is used as given. + 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``. From cfec1b078ba8d2af63118e3ffc65da5c112b8d23 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 5 Jun 2026 14:51:42 -0700 Subject: [PATCH 2/2] Fix line length --- Doc/library/argparse.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index dac09e5a0df6a3..7ecad466c80c9b 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1052,9 +1052,9 @@ is used when no command-line argument was present:: >>> parser.parse_args([]) Namespace(foo=42) -Because ``nargs='*'`` collects matched values into a list, an absent positional -argument yields an empty list (``[]``); a default of ``None`` is replaced by -``[]``, although any other default is used as given. +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 ``*``,