https://github.com/python/cpython/commit/95f6e1275b1c9de550d978cb2b4351cc4ed24fe4 commit: 95f6e1275b1c9de550d978cb2b4351cc4ed24fe4 branch: main author: Savannah Ostrowski <[email protected]> committer: savannahostrowski <[email protected]> date: 2025-11-05T22:46:30Z summary:
GH-108009: Add clarification of parser and argument defaults in argparse docs (#124154) Co-authored-by: C.A.M. Gerlach <[email protected]> files: M Doc/library/argparse.rst diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 9655db4f301a31..5a8f0bde2e385d 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2070,7 +2070,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') _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
