New submission from Antony Lee <anntzer....@gmail.com>:
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. ---------- components: Library (Lib) messages: 357733 nosy: Antony.Lee priority: normal severity: normal status: open title: argparse.BooleanOptionalAction should not add the default value to the help string by default versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38956> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com