From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 5 Nov 2025 22:52:22 +0000 (+0100) Subject: [3.14] GH-108009: Add clarification of parser and argument defaults in argparse docs... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=00087dc466e3711a2bb3b5e57cbb354302f9c60c;p=thirdparty%2FPython%2Fcpython.git [3.14] GH-108009: Add clarification of parser and argument defaults in argparse docs (GH-124154) (#141084) GH-108009: Add clarification of parser and argument defaults in argparse docs (GH-124154) (cherry picked from commit 95f6e1275b1c9de550d978cb2b4351cc4ed24fe4) Co-authored-by: Savannah Ostrowski Co-authored-by: C.A.M. Gerlach --- diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 0ee921e15260..2dca4a71a536 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2071,7 +2071,9 @@ Parser defaults >>> parser.parse_args(['736']) Namespace(bar=42, baz='badger', foo=736) - Note that parser-level defaults always override argument-level defaults:: + Note that defaults can be set at both the parser level using :meth:`set_defaults` + and at the argument level using :meth:`add_argument`. If both are called for the + same argument, the last default set for an argument is used:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', default='bar')