Skip to content

Commit 3d42446

Browse files
gh-155403: Document that store_true/store_false are affected by argument_default
1 parent 998b890 commit 3d42446

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Doc/library/argparse.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,20 @@ how the command-line arguments should be handled. The supplied actions are:
780780
* ``'store_true'`` and ``'store_false'`` - These are special cases of
781781
``'store_const'`` that respectively store the values ``True`` and ``False``
782782
with default values of ``False`` and
783-
``True``::
783+
``True``. Note that if ``argument_default`` is set to ``SUPPRESS``,
784+
these defaults are also suppressed::
784785

785786
>>> parser = argparse.ArgumentParser()
786787
>>> parser.add_argument('--foo', action='store_true')
787788
>>> parser.add_argument('--bar', action='store_false')
788789
>>> parser.add_argument('--baz', action='store_false')
789790
>>> parser.parse_args('--foo --bar'.split())
790791
Namespace(foo=True, bar=False, baz=True)
792+
>>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
793+
>>> parser.add_argument('--foo', action='store_true')
794+
>>> parser.add_argument('--bar', action='store_false')
795+
>>> parser.parse_args('--foo'.split())
796+
Namespace(foo=True) # bar and baz are suppressed (not present)
791797

792798
* ``'append'`` - This appends each argument value to a list.
793799
It is useful for allowing an option to be specified multiple times.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Document that ``'store_true'`` and ``'store_false'`` defaults are affected by
2+
``argument_default`` in the :mod:`argparse` documentation.

0 commit comments

Comments
 (0)