]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] GH-108009: Add clarification of parser and argument defaults in argparse docs...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 5 Nov 2025 22:52:22 +0000 (23:52 +0100)
committerGitHub <noreply@github.com>
Wed, 5 Nov 2025 22:52:22 +0000 (22:52 +0000)
GH-108009: Add clarification of parser and argument defaults in argparse docs (GH-124154)
(cherry picked from commit 95f6e1275b1c9de550d978cb2b4351cc4ed24fe4)

Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Doc/library/argparse.rst

index 0ee921e15260c4fe261d1ed6de9b44d5da11d229..2dca4a71a5361a9f02d3c5c0eeddbac5cf4fdfef 100644 (file)
@@ -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')