]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672) (GH...
authorŁukasz Langa <lukasz@langa.pl>
Tue, 17 Aug 2021 09:17:00 +0000 (11:17 +0200)
committerGitHub <noreply@github.com>
Tue, 17 Aug 2021 09:17:00 +0000 (11:17 +0200)
Co-authored-by: Micky Yun Chan <michan@redhat.com>.
(cherry picked from commit 1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f)

Co-authored-by: Maximilian Hils <git@maximilianhils.com>
Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS.d/next/Library/2021-08-09-13-17-10.bpo-38956.owWLNv.rst [new file with mode: 0644]

index ccb010d0d5cae536d6707600ec58efebbee62264..f45a2ed4d4dc77cfacb50dbbc86b9347c88b3df7 100644 (file)
@@ -875,7 +875,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,
index e1685443248ef224d6f2b3a08de056dd54f018c6..5d8bc1427c42784231b45f96f694ce1367b9fa58 100644 (file)
@@ -4259,6 +4259,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'),
     ]
@@ -4267,25 +4270,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)
 
         optional arguments:
-          -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 (file)
index 0000000..3f57c0e
--- /dev/null
@@ -0,0 +1 @@
+:class:`argparse.BooleanOptionalAction`'s default value is no longer printed twice when used with :class:`argparse.ArgumentDefaultsHelpFormatter`.