-
Notifications
You must be signed in to change notification settings - Fork 197
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
Consider using ObjectDictionaryError iso. NotImplementedError in export/import OD APIs #475
Comments
For context, quoting the relevant CPython docs:
|
That is incorrect, #469 only moved the code around. See
edit. This was the code that introduced it, 8 year ago: 7fdd90c |
Moreover, #469 did absolutely not just move code around; it was created for a specific behavioural change (closing the file), and it accidentally (?) introduced two behavioural changes. |
Yeah, you're right. I guess I simply copied the same logic has the other function to make them consistent and issue the same type exception as the other function, albeit of incorrect type. |
I support this. Not sure about |
Related, regarding the other uses of
|
One solution could be to introduce a new exception type, subclasses off of Another candidate could be
|
How about just using a generic I don't think it really matters much which exception we raise here, in terms of keeping compatibility. Because when a wrong file type is supplied, there is not much an application can "work around" to fix it. Catching specific exceptions is, in my experience, useful if you have an idea of what can be done to remedy a specific, expected failure. But what would that ever look like if the supplied file is in the wrong format? Silently retry with a different file? I don't think so. Such a failure is thus an "exceptional" condition, worthy of being simply thrown back at whoever supplied the file. If it was the user, then a file-picker was wrongly configured or a command line argument should have been better validated before. If it was programatically from application code, then that needs fixing by the developer, who doesn't care what exception type was printed on the console, but just checks the error message. |
Surely there is room for improvement here in general. Please point out specific locations in a PR, so we can discuss them individually. EDIT: Sorry, I misunderstood that you're suggesting a |
The same can be said about some of the other IOW, I think there is value in normalising the exceptions raised when importing (and possibly also exporting) ODs. I can create a draft PR so it is easier to discuss the proposed changes. Footnotes
|
Discovered while reviewing #469. (See #469 (comment).)
In most cases,
ObjectDictionaryError
is used for theexport_od
andimport_od
APIs, but for unsupported file formats, aNotImplementedError
is raised. This is unconventional;NotImplementedError
is not a good fit for such an error case, as it was designed for other purposes (see the CPython docs).The
NotImplementedError
inexport_od
is fairly new (introduced with #469), and has not been a part of a formal release; it can be changed without backwards compatibility concerns. Theraise
inimport_od
has been there longer, but these are (for now) undocumented, though public, APIs. One can argue that since they are undocumented, it may be ok to changeimport_od
as well.Consider switching to
ObjectDictionaryError
.The text was updated successfully, but these errors were encountered: