-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argparse.BooleanOptionalAction should not add the default value to the help string by default #83137
Comments
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
I think the fix is just a matter of not adding the default value to the help string. |
Hi, if it's possible can I take this issue? |
Hi I created a new pull request on Github |
Thanks, Max for pushing this across the finish line! ✨ 🍰 ✨ Closing this one. Further improvement of BooleanOptionalAction will be discussed in BPO-44587. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: