Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,20 @@ how the command-line arguments should be handled. The supplied actions are:
* ``'store_true'`` and ``'store_false'`` - These are special cases of
``'store_const'`` that respectively store the values ``True`` and ``False``
with default values of ``False`` and
``True``::
``True``. Note that if ``argument_default`` is set to ``SUPPRESS``,
these defaults are also suppressed::

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', action='store_true')
>>> parser.add_argument('--bar', action='store_false')
>>> parser.add_argument('--baz', action='store_false')
>>> parser.parse_args('--foo --bar'.split())
Namespace(foo=True, bar=False, baz=True)
>>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
>>> parser.add_argument('--foo', action='store_true')
>>> parser.add_argument('--bar', action='store_false')
>>> parser.parse_args('--foo'.split())
Namespace(foo=True) # bar and baz are suppressed (not present)
Comment on lines +792 to +796

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mention only arguments registered on the second parser

The second example replaces parser and registers only foo and bar, so baz is not suppressed—it does not exist on this parser at all. This makes the new explanation factually misleading; either register baz again or state only that bar is suppressed.

Useful? React with 👍 / 👎.


* ``'append'`` - This appends each argument value to a list.
It is useful for allowing an option to be specified multiple times.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Document that ``'store_true'`` and ``'store_false'`` defaults are affected by
``argument_default`` in the :mod:`argparse` documentation.
Loading