Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jjpapa36912 wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromjjpapa36912:fix-issue-#117941

Conversation

@jjpapa36912
Copy link

@jjpapa36912jjpapa36912 commentedApr 19, 2024
edited by bedevere-appbot
Loading

@ghost
Copy link

ghost commentedApr 19, 2024
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

@jjpapa36912
Copy link
Author

I was wondering if when does it review.

Copy link
Member

@encukouencukou left a comment
edited
Loading

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!
Copy link
Member

Choose a reason for hiding this comment

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

Please seethe devguide on how to write a NEWS entry.

@jjpapa36912
Copy link
Author

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.

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?

@encukou
Copy link
Member

If you can fix it properly, sure. It will not be easy.
As I said above, the PR needs tests and documentation for the new behaviour. When you write the tests, you'll probably discover many cases where this PR results in unexpected behaviour.

On the other hand, if we clearly say that adding--no- options directly doesn't work, there will be fewer fewer special cases that argparse needs to handle, test and document. Less code is better for everyone ;)

jjpapa36912 reacted with thumbs up emoji

@jjpapa36912
Copy link
Author

If you can fix it properly, sure. It will not be easy. As I said above, the PR needs tests and documentation for the new behaviour. When you write the tests, you'll probably discover many cases where this PR results in unexpected behaviour.

On the other hand, if we clearly say that adding--no- options directly doesn't work, there will be fewer fewer special cases that argparse needs to handle, test and document. Less code is better for everyone ;)

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?

@encukou
Copy link
Member

Right; I don't think that was the intent.
But, I can see someone trying the following and finding that it works for them (with a weird auto-added--no-no-foo option, which you can ignore):

>>>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:

You may also specify an arbitrary action by passing an Action subclass or other object that implements the same interface. TheBooleanOptionalAction is available inargparse and adds support for boolean actions such as--foo and--no-foo

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@encukouencukouencukou left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@jjpapa36912@encukou

[8]ページ先頭

©2009-2025 Movatter.jp