mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)
Co-authored-by: Micky Yun Chan <michan@redhat.com>
This commit is contained in:
parent
d84d2c4985
commit
1512bc21d6
3 changed files with 16 additions and 8 deletions
|
@ -876,7 +876,7 @@ class BooleanOptionalAction(Action):
|
||||||
_option_strings.append(option_string)
|
_option_strings.append(option_string)
|
||||||
|
|
||||||
if help is not None and default is not None:
|
if help is not None and default is not None:
|
||||||
help += f" (default: {default})"
|
help += " (default: %(default)s)"
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
option_strings=_option_strings,
|
option_strings=_option_strings,
|
||||||
|
|
|
@ -4281,6 +4281,9 @@ class TestHelpArgumentDefaults(HelpTestCase):
|
||||||
argument_signatures = [
|
argument_signatures = [
|
||||||
Sig('--foo', help='foo help - oh and by the way, %(default)s'),
|
Sig('--foo', help='foo help - oh and by the way, %(default)s'),
|
||||||
Sig('--bar', action='store_true', help='bar help'),
|
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('spam', help='spam help'),
|
||||||
Sig('badger', nargs='?', default='wooden', help='badger help'),
|
Sig('badger', nargs='?', default='wooden', help='badger help'),
|
||||||
]
|
]
|
||||||
|
@ -4289,25 +4292,29 @@ class TestHelpArgumentDefaults(HelpTestCase):
|
||||||
[Sig('--baz', type=int, default=42, help='baz help')]),
|
[Sig('--baz', type=int, default=42, help='baz help')]),
|
||||||
]
|
]
|
||||||
usage = '''\
|
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 + '''\
|
help = usage + '''\
|
||||||
|
|
||||||
description
|
description
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
spam spam help
|
spam spam help
|
||||||
badger badger help (default: wooden)
|
badger badger help (default: wooden)
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
--foo FOO foo help - oh and by the way, None
|
--foo FOO foo help - oh and by the way, None
|
||||||
--bar bar help (default: False)
|
--bar bar help (default: False)
|
||||||
|
--taz, --no-taz Whether to taz it (default: True)
|
||||||
|
--quux QUUX Set the quux (default: 42)
|
||||||
|
|
||||||
title:
|
title:
|
||||||
description
|
description
|
||||||
|
|
||||||
--baz BAZ baz help (default: 42)
|
--baz BAZ baz help (default: 42)
|
||||||
'''
|
'''
|
||||||
version = ''
|
version = ''
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
:class:`argparse.BooleanOptionalAction`'s default value is no longer printed twice when used with :class:`argparse.ArgumentDefaultsHelpFormatter`.
|
Loading…
Add table
Add a link
Reference in a new issue