[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 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:22 +01:00 committed by GitHub
parent 5561837085
commit 00087dc466
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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')