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
Decoding exceptions thrown by ujson are not drop-in compatible #497
Comments
Sounds reasonable. I think I'd prefer the second option - to have our own |
PR welcome! |
I'm giving that a shot. Any advice on where to put the |
I'd have thought the header file |
That'd work, although having a |
Hmm, you're right. I believe that the intention is to keep the Python binding separate from the json reading/writing. Honestly, the separate header sounds best. |
orjson also subclasses Is it worth doing the same? (If so, could be done after #498.) |
Perhaps, although at least that's not a compatibility issue since the built-in |
So as to match the behaviour of Python's json library. Fixes #497
@hugovk Regarding (By the way, confusingly and contradicting the code I linked above, |
Thanks, we can skip |
What did you do?
What did you expect to happen?
The error gets caught and printed. This is the behaviour when using
import json
. Although I haven't tested them, it appears that other drop-in replacements like hyperjson and orjson should also behave like this.What actually happened?
With
import ujson as json
, aValueError
exception followed by anAttributeError
becausemodule 'ujson' has no attribute 'JSONDecodeError'
.What versions are you using?
Solution
ujson should either effectively
from json import JSONDecodeError
(hyperjson does this) or define its ownJSONDecodeError
(orjson does this) and then raise that instead of aValueError
. AsJSONDecodeError
is a subclass ofValueError
, this would not break existing code usingexcept ValueError
.The text was updated successfully, but these errors were encountered: