Skip to content

Conversation

@michiboo
Copy link
Contributor

@michiboo michiboo commented Dec 3, 2019

Signed-off-by: Micky Yun Chan (michiboo): [email protected]

https://bugs.python.org/issue38956

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

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!

@michiboo
Copy link
Contributor Author

michiboo commented Dec 4, 2019

I already signed the CLA yesterday

@shihai1991
Copy link
Member

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
Copy link
Contributor Author

Hi, I updated the test

@shihai1991
Copy link
Member

@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, thanks.

@michiboo
Copy link
Contributor Author

michiboo commented Apr 8, 2020

bump

@csabella csabella requested a review from rhettinger May 23, 2020 18:23
@rhettinger rhettinger self-assigned this May 24, 2020
option_string = '--no-' + option_string[2:]
_option_strings.append(option_string)

if help is not None and default is not None:
Copy link
Contributor

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bedevere-bot
Copy link

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

I have made the requested changes; please review again

@bedevere-bot
Copy link

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 00:43
@michiboo
Copy link
Contributor Author

bump

@ambv
Copy link
Contributor

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

Development

Successfully merging this pull request may close these issues.

7 participants