https://github.com/python/cpython/commit/70bc048e5cc5ae28663381bdc906292b5c5bf334
commit: 70bc048e5cc5ae28663381bdc906292b5c5bf334
branch: main
author: Dmitry Voropaev <[email protected]>
committer: savannahostrowski <[email protected]>
date: 2026-09-28T16:03:14Z
summary:

gh-110131: Document how a non-empty default works with append and extend 
(#158155)

files:
M Doc/library/argparse.rst

diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index c88c10030fb369..58f61a06d0512c 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -791,9 +791,9 @@ how the command-line arguments should be handled. The 
supplied actions are:
 
 * ``'append'`` - This appends each argument value to a list.
   It is useful for allowing an option to be specified multiple times.
-  If the default value is a non-empty list, the parsed value will start
-  with the default list's elements and any values from the command line
-  will be appended after those default values. Example usage::
+  If the default value is a non-empty list, the parsed value for the option
+  will start with the default list's elements and any values from the
+  command line will be appended after those default values. Example usage::
 
     >>> parser = argparse.ArgumentParser()
     >>> parser.add_argument('--foo', action='append', default=['0'])
@@ -818,12 +818,16 @@ how the command-line arguments should be handled. The 
supplied actions are:
   value ``'+'`` or ``'*'``.
   Note that when nargs_ is ``None`` (the default) or ``'?'``, each
   character of the argument string will be appended to the list.
+  If the default value is a non-empty list, the parsed value for the option
+  will start with the default list's elements and any values from the
+  command line will be appended after those default values.
   Example usage::
 
     >>> parser = argparse.ArgumentParser()
-    >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
+    >>> parser.add_argument("--foo", action="extend", nargs="+", type=str,
+    ...                     default=["d1"])
     >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
-    Namespace(foo=['f1', 'f2', 'f3', 'f4'])
+    Namespace(foo=['d1', 'f1', 'f2', 'f3', 'f4'])
 
   .. versionadded:: 3.8
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to