Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1512bc2

Browse files
mhilsmichiboo
andauthored
bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)
Co-authored-by: Micky Yun Chan <[email protected]>
1 parent d84d2c4 commit 1512bc2

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

Lib/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ def __init__(self,
876876
_option_strings.append(option_string)
877877

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

881881
super().__init__(
882882
option_strings=_option_strings,

Lib/test/test_argparse.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4281,6 +4281,9 @@ class TestHelpArgumentDefaults(HelpTestCase):
42814281
argument_signatures = [
42824282
Sig('--foo', help='foo help - oh and by the way, %(default)s'),
42834283
Sig('--bar', action='store_true', help='bar help'),
4284+
Sig('--taz', action=argparse.BooleanOptionalAction,
4285+
help='Whether to taz it', default=True),
4286+
Sig('--quux', help="Set the quux", default=42),
42844287
Sig('spam', help='spam help'),
42854288
Sig('badger', nargs='?', default='wooden', help='badger help'),
42864289
]
@@ -4289,25 +4292,29 @@ class TestHelpArgumentDefaults(HelpTestCase):
42894292
[Sig('--baz', type=int, default=42, help='baz help')]),
42904293
]
42914294
usage = '''\
4292-
usage: PROG [-h] [--foo FOO] [--bar] [--baz BAZ] spam [badger]
4295+
usage: PROG [-h] [--foo FOO] [--bar] [--taz | --no-taz] [--quux QUUX]
4296+
[--baz BAZ]
4297+
spam [badger]
42934298
'''
42944299
help = usage + '''\
42954300
42964301
description
42974302
42984303
positional arguments:
4299-
spam spam help
4300-
badger badger help (default: wooden)
4304+
spam spam help
4305+
badger badger help (default: wooden)
43014306
43024307
options:
4303-
-h, --help show this help message and exit
4304-
--foo FOO foo help - oh and by the way, None
4305-
--bar bar help (default: False)
4308+
-h, --help show this help message and exit
4309+
--foo FOO foo help - oh and by the way, None
4310+
--bar bar help (default: False)
4311+
--taz, --no-taz Whether to taz it (default: True)
4312+
--quux QUUX Set the quux (default: 42)
43064313
43074314
title:
43084315
description
43094316
4310-
--baz BAZ baz help (default: 42)
4317+
--baz BAZ baz help (default: 42)
43114318
'''
43124319
version = ''
43134320

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:class:`argparse.BooleanOptionalAction`'s default value is no longer printed twice when used with :class:`argparse.ArgumentDefaultsHelpFormatter`.

0 commit comments

Comments
 (0)