8000 GH-108009: Add clarification of parser and argument defaults in argparse docs by savannahostrowski · Pull Request #124154 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-108009: Add clarification of parser and argument defaults in argparse docs #124154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Next Next commit
Add additional clarification on defaults
  • Loading branch information
savannahostrowski committed Sep 17, 2024
commit 8c47ebfcebb622d10be1be89a6a93891ac3ce2bc
5 changes: 4 additions & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,10 @@ 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 provided for the
same attribute, the order of setting these defaults determines which one takes
precedence. The last default set for an attribute is the one that is used:

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', default='bar')
Expand Down
0