Skip to content

Commit 95f6e12

Browse files
pythonGH-108009: Add clarification of parser and argument defaults in argparse docs (python#124154)
Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent f0ab07f commit 95f6e12

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Doc/library/argparse.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,9 @@ Parser defaults
20702070
>>> parser.parse_args(['736'])
20712071
Namespace(bar=42, baz='badger', foo=736)
20722072

2073-
Note that parser-level defaults always override argument-level defaults::
2073+
Note that defaults can be set at both the parser level using :meth:`set_defaults`
2074+
and at the argument level using :meth:`add_argument`. If both are called for the
2075+
same argument, the last default set for an argument is used::
20742076

20752077
>>> parser = argparse.ArgumentParser()
20762078
>>> parser.add_argument('--foo', default='bar')

0 commit comments

Comments
 (0)