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
bpo-38956: remove default option from help string in argparse #17447
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
2c662e2
to
de576c3
Signed-off-by: Micky Yun Chan (michiboo): <chanmickyyun@gmail.com>
I already signed the CLA yesterday |
@michiboo Thanks for your contribute. |
67f2c6e
to
867b523
Hi, I updated the test |
@michiboo Thanks. |
bump |
@@ -873,9 +873,6 @@ def __init__(self, | |||
option_string = '--no-' + option_string[2:] | |||
_option_strings.append(option_string) | |||
|
|||
if help is not None and default is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the effect of this edit is too broad. Instead, focus on making sure the default only prints once when the formatter_class is set to ArgumentDefaultsHelpFormatter. When formatter_class isn't set, the default still needs to be shown.
Given this script:
from argparse import *
parser = ArgumentParser()
parser.add_argument("--foo", action=BooleanOptionalAction, help="Whether to foo it", default=False)
parser.add_argument("--quux", help="Set the quux", default=42)
print(parser.parse_args())
We still want this output:
$ py tmp.py --help
usage: tmp.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: False)
--quux QUUX Set the quux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the requested changes; please review again
Hi I have updated the code in add action function since it is not possible to get formatter class in action object, ArgumentDefaultsHelpFormatter already add default value and that was the origin problem which result in duplicate default value in the help string. Now with the default formatter class it can also show the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rhettinger could you speak on why the default should be displayed for BooleanOptionalArgument out-of-the-box whereas all other shipped actions require setting formatter_class=ArgumentDefaultsHelpFormatter
? I do find that showing the default value is useful but it seems to break the expected separation of responsibility between action and formatter.
I ask about this since I have a different bug which would be fixed if BooleanOptionalArgument were to no longer try to add defaults on its own. If BooleanOptionalArgument should continue to do that formatting, though, I could extract the code from ArgumentDefaultsHelpFormatter and have both ArgumentDefaultsHelpFormatter and BooleanOptionalArgument use it which would likely fix my issue, this issue, and a similar class of issues that we just haven't encountered yet.
Make sure the default still shown when a formatter_class isn't specified.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @rhettinger: please review the changes made to this pull request. |
bump |
Closing in favor of GH-27672. |
Signed-off-by: Micky Yun Chan (michiboo): chanmickyyun@gmail.com
https://bugs.python.org/issue38956
The text was updated successfully, but these errors were encountered: