-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-117941: Fix argparse issue-Changed call method of BooleanOptionalAction class in argparse.py #117941 #118103
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
base: main
Are you sure you want to change the base?
Conversation
jjpapa36912
commented
Apr 19, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: BooleanOptionalAction does not correctly resolve arguments that are defined as starting with "--no-" #117941
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
I was wondering if when does it review. |
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.
The PR needs tests and documentation for the new behaviour.
However, I'm not convinced that we should do this; I think it would be better to deprecate adding boolean options that start with --no-
. The auto-added --no-no-
option itself is surprising.
@@ -0,0 +1 @@ | |||
write! |
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.
Please see the devguide on how to write a NEWS entry.
Thank you for answer my question. I understand your explanation. But I think that to eliminating exception or abnormal situation is very important. In that sense, isn't it better to fix the code? |
If you can fix it properly, sure. It will not be easy. On the other hand, if we clearly say that adding |
Oh, thank you for your answer. I have one question. If the option string starts with "--no-" I think the current BoolOptionalAction always returns "False". What do you think about this? |
Right; I don't think that was the intent. >>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--no-foo', default=True, action=argparse.BooleanOptionalAction)
>>> parser.parse_args()
Namespace(no_foo=True)
>>> parser.parse_args(['--no-foo'])
Namespace(no_foo=False) The documentation doesn't clearly say that this is wrong:
|