Skip to content

Suggestion for argparse: raise a warning on type=bool #126676

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

Open
user202729 opened this issue Nov 11, 2024 · 1 comment
Open

Suggestion for argparse: raise a warning on type=bool #126676

user202729 opened this issue Nov 11, 2024 · 1 comment
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir

Comments

@user202729
Copy link

user202729 commented Nov 11, 2024

Feature or enhancement

Proposal:

There has been complaints about type=bool usage in argparse: #81745 #83348 #71181 . See also https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse

while we may not want to actually change the behavior (given existing code on the wild might use it, as mentioned in previous discussions), what about raise a warning? Or is that also too intrusive?

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

@user202729 user202729 added the type-feature A feature request or enhancement label Nov 11, 2024
@picnixz picnixz added the stdlib Python modules in the Lib dir label Nov 11, 2024
@savannahostrowski
Copy link
Member

savannahostrowski commented Nov 17, 2024

I'd probably be more inclined to document recipes/patterns to achieve the desired result if we need additional materials here since we have already documented that bool() is not recommended as a type converter.

The bool() function is not recommended as a type converter. All it does is convert empty strings to False and non-empty strings to True. This is usually not what is desired.

My concern is that adding a warning here could still break tests, etc.

@savannahostrowski savannahostrowski added docs Documentation in the Doc dir and removed type-feature A feature request or enhancement labels Nov 17, 2024
@savannahostrowski savannahostrowski moved this to Doc issues in Argparse issues Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir
Projects
Status: Doc issues
Status: Todo
Development

No branches or pull requests

3 participants