From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:15:21 +0000 (+0200) Subject: [3.12] GH-87358: Add clarification about nargs and default argparse behaviour (GH... X-Git-Tag: v3.12.7~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=10cf0b8cafcb951d09291d022525a1e4460c1054;p=thirdparty%2FPython%2Fcpython.git [3.12] GH-87358: Add clarification about nargs and default argparse behaviour (GH-124094) (#124441) Co-authored-by: Savannah Ostrowski --- diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 4f4a29bfd55c..8ed44fc809f7 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1121,6 +1121,9 @@ is used when no command-line argument was present:: >>> parser.parse_args([]) Namespace(foo=42) +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``. Providing ``default=argparse.SUPPRESS`` causes no attribute to be added if the command-line argument was not present::