-
-
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: creating an already defined subparsers does not raises an exception #59061
Comments
With this patch, it raises an ArgumentException, instead of overwriting previous subparser without notice. Regards. |
Thanks for the report and patch. However, since there is no del_parser method, I'm inclined to think that this is not a bug. That is, the ability to overwrite a previously defined subparser could be considered a feature. If Steven does consider it a bug, I think it can only be fixed in 3.3, since to do otherwise could needlessly break currently-working programs. If it is not a bug, add_parser's behavior when a parser already exist should be documented. |
Yeah, overwriting the existing parser is probably not typically what the user intended. However, I could see someone doing this if, say, they had a parser designed by another module writer, and they wanted to use it but just change one of the sub-parsers or something like that. But a "set_parser" method would probably make more sense for this use case than "add_parser". I guess my recommendation is to add a "set_parser" method that replaces the old parser (like "add_parser" does now), and then issue deprecation warnings in "add_parser" if a parser with the given name is present (like the patch does, but with deprecation warnings instead of exceptions). We could then turn the warnings into errors in a few releases. |
The open patch deprecates overriding the parser with add_parser, but it does not add the new set_parser method that Steven suggested. |
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: