Fix #1868: elpy-goto-definition breaks with python 3.9#1902
Fix #1868: elpy-goto-definition breaks with python 3.9#1902galaunay wants to merge 2 commits intojorgenschaefer:masterfrom
Conversation
Original solution from @akshaybadola here: jorgenschaefer#1868
|
|
||
| """ | ||
| self.stdout.write(json.dumps(kwargs) + "\n") | ||
| self.stdout.write(json.dumps(kwargs, default=self.json_defaults) + "\n") |
There was a problem hiding this comment.
The docs for json.dumps say that it should raise a TypeError if the object cannot be serializable, (In this case, all other objects that are not Path and are not primitive types will be encoded as null since json_defaults is implicitly returning None.
>>> import json
>>> json.dumps(None)
'null'
>>> Also relevant CPython source code that shows this will happen
I don't think this is the intended outcome?
There was a problem hiding this comment.
The docs for
json.dumpssay that it should raise aTypeErrorif the object cannot be serializable, (In this case, all other objects that are notPathand are not primitive types will be encoded asnullsincejson_defaultsis implicitly returningNone.>>> import json >>> json.dumps(None) 'null' >>>Also relevant CPython source code that shows this will happen
I don't think this is the intended outcome?
Hi @gopar. Sorry I've been extremely busy. Yes, definitely that shouldn't be there. I had completely overlooked that and forgot to return the default value. It should be:
def json_defaults(x):
if isinstance(x, Path):
return str(x)
else:
return json.dumps(x)See docstring of default in JSONEncoder.
Actually pydantic would be a good approach to go for it as it is primarily a parsing library. Though I think @gfederix's PR (See discussion in #1895) requires a few fixes.
At this point I'm not sure which things to refactor, for example in rpc.py, as there are parallel changes in #1895 which are not yet merged. Any suggestions?
Original solution from @akshaybadola here: #1868