This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Antony.Lee
Recipients Antony.Lee
Date 2019-12-02.23:03:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1575327804.72.0.272027136625.issue38956@roundup.psfhosted.org>
In-reply-to
Content
https://bugs.python.org/issue8538 recently added to Py3.9 a much welcome addition to argparse, namely the capability to generate --foo/--no-foo flag pairs.  A small issue with the implementation is that it *always* appends the default value to the help string (if any):

    if help is not None and default is not None:
        help += f" (default: {default})"

This is inconsistent with other action classes, and results in the defaults being printed twice if using ArgumentsDefaultHelpFormatter (which is the documented way to include the defaults in the help text):

    from argparse import *
    parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument("--foo", action=BooleanOptionalAction, help="Whether to foo it", default=True)
    parser.add_argument("--quux", help="Set the quux", default=42)
    print(parser.parse_args())

yields

    usage: foo.py [-h] [--foo | --no-foo] [--quux QUUX]

    optional arguments:
      -h, --help       show this help message and exit
      --foo, --no-foo  Whether to foo it (default: True) (default: True)  # <--- HERE
      --quux QUUX      Set the quux (default: 42)

I think the fix is just a matter of not adding the default value to the help string.
History
Date User Action Args
2019-12-02 23:03:25Antony.Leesetrecipients: + Antony.Lee
2019-12-02 23:03:24Antony.Leesetmessageid: <1575327804.72.0.272027136625.issue38956@roundup.psfhosted.org>
2019-12-02 23:03:24Antony.Leelinkissue38956 messages
2019-12-02 23:03:24Antony.Leecreate