Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def __init__(self,
_option_strings.append(option_string)

if help is not None and default is not None:
help += f" (default: {default})"
help += " (default: %(default)s)"

super().__init__(
option_strings=_option_strings,
Expand Down
21 changes: 14 additions & 7 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4281,6 +4281,9 @@ class TestHelpArgumentDefaults(HelpTestCase):
argument_signatures = [
Sig('--foo', help='foo help - oh and by the way, %(default)s'),
Sig('--bar', action='store_true', help='bar help'),
Sig('--taz', action=argparse.BooleanOptionalAction,
help='Whether to taz it', default=True),
Sig('--quux', help="Set the quux", default=42),
Sig('spam', help='spam help'),
Sig('badger', nargs='?', default='wooden', help='badger help'),
]
Expand All @@ -4289,25 +4292,29 @@ class TestHelpArgumentDefaults(HelpTestCase):
[Sig('--baz', type=int, default=42, help='baz help')]),
]
usage = '''\
usage: PROG [-h] [--foo FOO] [--bar] [--baz BAZ] spam [badger]
usage: PROG [-h] [--foo FOO] [--bar] [--taz | --no-taz] [--quux QUUX]
[--baz BAZ]
spam [badger]
'''
help = usage + '''\

description

positional arguments:
spam spam help
badger badger help (default: wooden)
spam spam help
badger badger help (default: wooden)

options:
-h, --help show this help message and exit
--foo FOO foo help - oh and by the way, None
--bar bar help (default: False)
-h, --help show this help message and exit
--foo FOO foo help - oh and by the way, None
--bar bar help (default: False)
--taz, --no-taz Whether to taz it (default: True)
--quux QUUX Set the quux (default: 42)

title:
description

--baz BAZ baz help (default: 42)
--baz BAZ baz help (default: 42)
'''
version = ''

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`argparse.BooleanOptionalAction`'s default value is now longer printed twice when used with :class:`argparse.ArgumentDefaultsHelpFormatter`.