[3.13] GH-108009: Add clarification of parser and argument defaults in argparse docs (GH-124154) (#141085)

GH-108009: Add clarification of parser and argument defaults in argparse docs (GH-124154)
(cherry picked from commit 95f6e1275b)

Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
Miss Islington (bot) 2025-11-05 23:52:43 +01:00 committed by GitHub
parent fc059dbe55
commit f671739fdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1965,7 +1965,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')