-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
argparse.BooleanOptionalAction accept and silently discard its the const argument #85039
Comments
The action is used to store None, True or False when an argument like --foo or --no-foo is given to the cli so it has no used for this action, but it is accepted without warning: Python 3.10.0a0 (heads/bpo-wip:6e23a9c82b, Jun 4 2020, 13:41:35)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', const='this_is_not_used', action=argparse.BooleanOptionalAction)
BooleanOptionalAction(option_strings=['--foo', '--no-foo'], dest='foo', nargs=0, const=None, default=None, type=None, choices=None, help=None, metavar=None)
>>> args = parser.parse_args()
>>> args
Namespace(foo=None) We could either always refuse this argument, or accepted and raise ValueError if it is different than None. The attached PR does the first. |
ISTM this should be addressed through documentation rather than by breaking currently deployed code that may have specified a default that already matches what the action does. |
argparse.BooleanOptionalAction was introduced in Python3.9 so there is no code there should be no code that already rely on it. |
Right. Go ahead :-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: