Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

@michiboo
Copy link
Contributor

@michiboo michiboo commented Dec 3, 2019

Signed-off-by: Micky Yun Chan (michiboo): chanmickyyun@gmail.com

https://bugs.python.org/issue38956

@the-knights-who-say-ni
Copy link

@the-knights-who-say-ni the-knights-who-say-ni commented Dec 3, 2019

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 Missing

Our records indicate the following people have not signed the CLA:

@michiboo

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
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Signed-off-by: Micky Yun Chan (michiboo): <chanmickyyun@gmail.com>
@michiboo michiboo force-pushed the remove_default branch from de576c3 to bbb941b Dec 3, 2019
@michiboo
Copy link
Contributor Author

@michiboo michiboo commented Dec 4, 2019

I already signed the CLA yesterday

@shihai1991
Copy link
Member

@shihai1991 shihai1991 commented Dec 9, 2019

@michiboo Thanks for your contribute.
just an small advice: pls adding a unit test to against this scenario(Looks adding test case from the bpo-38956 in https://github.com/python/cpython/blob/master/Lib/test/test_argparse.py#L4182 is good enough)

@michiboo michiboo force-pushed the remove_default branch 7 times, most recently from 67f2c6e to 867b523 Dec 10, 2019
@michiboo
Copy link
Contributor Author

@michiboo michiboo commented Dec 10, 2019

Hi, I updated the test

@shihai1991
Copy link
Member

@shihai1991 shihai1991 commented Dec 10, 2019

@michiboo Thanks.
@rhettinger Hi, raymond. I checked that https://github.com/python/cpython/blob/master/Lib/argparse.py#L697 is conflict with https://github.com/python/cpython/blob/master/Lib/argparse.py#L876, so removing the redundant code is fine to me. Pls review this PR if your have free time. Thank you.

Copy link
Member

@shihai1991 shihai1991 left a comment

LGTM now, thanks.

@michiboo
Copy link
Contributor Author

@michiboo michiboo commented Apr 8, 2020

bump

@csabella csabella requested a review from rhettinger May 23, 2020
@rhettinger rhettinger self-assigned this May 24, 2020
@@ -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:
Copy link
Contributor

@rhettinger rhettinger May 24, 2020

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

Copy link
Contributor Author

@michiboo michiboo May 24, 2020

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.

Copy link
Contributor

@abadger abadger Jul 8, 2021

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.

Copy link
Contributor

@rhettinger rhettinger left a comment

Make sure the default still shown when a formatter_class isn't specified.

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented May 24, 2020

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. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@michiboo
Copy link
Contributor Author

@michiboo michiboo commented May 25, 2020

I have made the requested changes; please review again

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented May 25, 2020

Thanks for making the requested changes!

@rhettinger: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from rhettinger May 25, 2020
@michiboo
Copy link
Contributor Author

@michiboo michiboo commented Jun 29, 2020

bump

@ambv
Copy link
Contributor

@ambv ambv commented Aug 16, 2021

Closing in favor of GH-27672.

@ambv ambv closed this Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants