gh-126068: Fix exceptions in the argparse module#126069
gh-126068: Fix exceptions in the argparse module#126069serhiy-storchaka merged 5 commits intopython:mainfrom
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.
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. |
tomasr8
left a comment
There was a problem hiding this comment.
LGTM! I agree these error messages should not be i18n'd.
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
savannahostrowski
left a comment
There was a problem hiding this comment.
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.