diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index b2318ddace8514b..c12c11f88744711 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -780,7 +780,8 @@ 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') @@ -788,6 +789,11 @@ how the command-line arguments should be handled. The supplied actions are: >>> 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) * ``'append'`` - This appends each argument value to a list. It is useful for allowing an option to be specified multiple times. diff --git a/Misc/NEWS.d/next/Documentation/2026-08-09-12-00-00.gh-issue-155403.wX8kR2.rst b/Misc/NEWS.d/next/Documentation/2026-08-09-12-00-00.gh-issue-155403.wX8kR2.rst new file mode 100644 index 000000000000000..a1099c8397d8f66 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2026-08-09-12-00-00.gh-issue-155403.wX8kR2.rst @@ -0,0 +1,2 @@ +Document that ``'store_true'`` and ``'store_false'`` defaults are affected by +``argument_default`` in the :mod:`argparse` documentation.