summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2021-08-16 21:42:21 (GMT)
committerGitHub <noreply@github.com>2021-08-16 21:42:21 (GMT)
commit1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f (patch)
treef05667cbf2a17004fcc20f01d48332558460c16a
parentd84d2c4985457733602d46dc4ee77290da4e9539 (diff)
downloadcpython-1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f.zip
cpython-1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f.tar.gz
cpython-1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f.tar.bz2
bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)
Co-authored-by: Micky Yun Chan <michan@redhat.com>
-rw-r--r--Lib/argparse.py2
-rw-r--r--Lib/test/test_argparse.py21
-rw-r--r--Misc/NEWS.d/next/Library/2021-08-09-13-17-10.bpo-38956.owWLNv.rst1
3 files changed, 16 insertions, 8 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 33c5d70..d5a0afb 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -876,7 +876,7 @@ class BooleanOptionalAction(Action):
_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,
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 93ac0c3..d369d0f 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -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'),
]
@@ -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 = ''
diff --git a/Misc/NEWS.d/next/Library/2021-08-09-13-17-10.bpo-38956.owWLNv.rst b/Misc/NEWS.d/next/Library/2021-08-09-13-17-10.bpo-38956.owWLNv.rst
new file mode 100644
index 0000000..3f57c0e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-08-09-13-17-10.bpo-38956.owWLNv.rst
@@ -0,0 +1 @@
+:class:`argparse.BooleanOptionalAction`'s default value is no longer printed twice when used with :class:`argparse.ArgumentDefaultsHelpFormatter`.