-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-126068: Fix exceptions in the argparse module #126069
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-126068: Fix exceptions in the argparse module #126069
Conversation
* Only error messages for ArgumentError and ArgumentTypeError are now translated. * ArgumentError is now only used for command line errors, not for logical errors in the program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that this wouldn't break code in the wild that catch those? ArgumentError
is a public exception (exposed in __all__
) so raising ValueError
instead might break code that have except ArgumentError
(if they looked at the source code).
I don't mind not translating them, but I'm not very comfortable with changing them like that without a more visible changelog (namely, by adding a true What's New entry).
I am sure that this will not break working program. ArgumentError is an exception for command line errors, it is not appropriate for logical errors. The working program should not contain logical errors, so it would not be affected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I agree these error messages should not be i18n'd.
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM. Just a couple comments!
Misc/NEWS.d/next/Library/2024-10-28-11-33-59.gh-issue-126068.Pdznm_.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
On other hand, if we change types of exceptions, we can also change some ValueError to TypeError when the latter is more appropriate -- when a required argument is missed or duplicated, or incorrect type of argument is passed. TypeError is already used for some of such errors, and it is also raised implicitly for such types of errors. |
Thank you for your review @savannahostrowski. I reverted changes to the NEWS file, because we should use full qualified names of exceptions in this case, and it will be too verbose. There are already links to the argparse module, so new links will not add much value. |
FYI: you can use :exc:`~argparse.ArgumentError` |
Yes, of course. But this is much noise for little benefit. |
* Only error messages for ArgumentError and ArgumentTypeError are now translated. * ArgumentError is now only used for command line errors, not for logical errors in the program. * TypeError is now raised instead of ValueError for some logical errors.
* Only error messages for ArgumentError and ArgumentTypeError are now translated. * ArgumentError is now only used for command line errors, not for logical errors in the program. * TypeError is now raised instead of ValueError for some logical errors.
Uh oh!
There was an error while loading. Please reload this page.