[Python-checkins] bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)
miss-islington
webhook-mailer at python.org
Tue Aug 17 05:40:50 EDT 2021
https://github.com/python/cpython/commit/6f6648e436d02bce0e49ba82f4377c0d2f586f0f
commit: 6f6648e436d02bce0e49ba82f4377c0d2f586f0f
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-08-17T02:40:41-07:00
summary:
bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)
Co-authored-by: Micky Yun Chan <michan at redhat.com>
(cherry picked from commit 1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f)
Co-authored-by: Maximilian Hils <git at maximilianhils.com>
files:
A Misc/NEWS.d/next/Library/2021-08-09-13-17-10.bpo-38956.owWLNv.rst
M Lib/argparse.py
M Lib/test/test_argparse.py
diff --git a/Lib/argparse.py b/Lib/argparse.py
index e3a49e74fa8d1..2ded39a0d341a 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -875,7 +875,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,
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 0994e70e65e1c..f453f6064b3ae 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -4262,6 +4262,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'),
]
@@ -4270,25 +4273,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 0000000000000..3f57c0ea5d5a3
--- /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`.
More information about the Python-checkins
mailing list