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

gh-117941: Reject option names starting with "--no-" in argparse.BooleanOptionalAction #125894

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Oct 23, 2024

…e.BooleanOptionalAction

They never worked correctly.
@serhiy-storchaka serhiy-storchaka force-pushed the argparse-BooleanOptionalAction-no-no branch from 51bbf5e to 714c456 Compare October 23, 2024 18:09
Copy link
Member

@savannahostrowski savannahostrowski left a comment

Choose a reason for hiding this comment

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

LGTM, but I think we should also update the documentation to reflect that --no-foo is no longer supported, right? The blurb from the docs:

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

@serhiy-storchaka
Copy link
Member Author

It never was supported. Just now you will get an error instead of wrong result when you use BooleanOptionalAction in the way it was not supposed to be used.

@savannahostrowski
Copy link
Member

savannahostrowski commented Oct 27, 2024

Right, but isn't the text I mentioned above suggesting that --no-foo can be used with BooleanOptionalAction? After this PR is merged, this is no longer recommended, as you'll get an error, so shouldn't we remove this as an example in the documentation?

@serhiy-storchaka
Copy link
Member Author

but isn't the text I mentioned above suggesting that --no-foo can be used with BooleanOptionalAction?

Read it in the context. The following example shows that it creates action for --no-foo when '--foo' is passed to add_argument().

@savannahostrowski
Copy link
Member

savannahostrowski commented Nov 5, 2024

Yeah, I see the example. It just sort of reads a bit unclear to me and implies that I should be able to create a parser with:
parser.add_argument('--no-foo', action=argparse.BooleanOptionalAction), which is no longer the case. My comment was more about creating clarity in the docs that --no- prefixed options are not supported.

@serhiy-storchaka
Copy link
Member Author

I do not see anything that implies that '--no-foo' works. And it never worked.

@serhiy-storchaka
Copy link
Member Author

Thank you for your review @savannahostrowski.

@serhiy-storchaka serhiy-storchaka merged commit 79805d2 into python:main Nov 11, 2024
36 checks passed
@serhiy-storchaka serhiy-storchaka deleted the argparse-BooleanOptionalAction-no-no branch November 11, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants