From cb2e693916edab4acc1189bcd643220f40e598c3 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 14 Sep 2024 14:12:07 -0700 Subject: [PATCH 1/4] add clarification about nargs and default --- Doc/library/argparse.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index aa1341c8d4d4a8..8f7df2955d5760 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1122,6 +1122,8 @@ is used when no command-line argument was present:: >>> parser.parse_args([]) Namespace(foo=42) +For other nargs_ values, the argument is treated as a required argument and +the default_ value is ignored. Providing ``default=argparse.SUPPRESS`` causes no attribute to be added if the command-line argument was not present:: From 16c45cd796d9d80b85ad85407393f6b49218a724 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 14 Sep 2024 14:17:30 -0700 Subject: [PATCH 2/4] fix trailing whitespace --- Doc/library/argparse.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 8f7df2955d5760..105da07b201bed 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1123,7 +1123,7 @@ is used when no command-line argument was present:: Namespace(foo=42) For other nargs_ values, the argument is treated as a required argument and -the default_ value is ignored. +the default_ value is ignored. Providing ``default=argparse.SUPPRESS`` causes no attribute to be added if the command-line argument was not present:: From 770b73280734a8adc819efadc8c0b7af4ef695e8 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sun, 22 Sep 2024 15:37:38 -0700 Subject: [PATCH 3/4] update phrasing for clarity --- Doc/library/argparse.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 105da07b201bed..46c0cad755ab60 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1122,8 +1122,9 @@ is used when no command-line argument was present:: >>> parser.parse_args([]) Namespace(foo=42) -For other nargs_ values, the argument is treated as a required argument and -the default_ value is ignored. +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:: From 3bfd5ad0c428df48f5fe3d411b23152ddd1bfe8e Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sun, 22 Sep 2024 15:39:53 -0700 Subject: [PATCH 4/4] appease linter --- Doc/library/argparse.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 46c0cad755ab60..b30d92d2c3df34 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1122,8 +1122,8 @@ 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 ``*``, +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