Message357733
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. |
|
Date |
User |
Action |
Args |
2019-12-02 23:03:25 | Antony.Lee | set | recipients:
+ Antony.Lee |
2019-12-02 23:03:24 | Antony.Lee | set | messageid: <1575327804.72.0.272027136625.issue38956@roundup.psfhosted.org> |
2019-12-02 23:03:24 | Antony.Lee | link | issue38956 messages |
2019-12-02 23:03:24 | Antony.Lee | create | |
|