diff --git a/elpy/json_encoder.py b/elpy/json_encoder.py new file mode 100644 index 000000000..43e7d2050 --- /dev/null +++ b/elpy/json_encoder.py @@ -0,0 +1,10 @@ +import json +import pathlib + + +class JSONEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, pathlib.Path): + return str(o) + else: + return super().default(o) diff --git a/elpy/rpc.py b/elpy/rpc.py index 07b2ce97e..33c098e07 100644 --- a/elpy/rpc.py +++ b/elpy/rpc.py @@ -10,6 +10,7 @@ import json import sys import traceback +from .json_encoder import JSONEncoder class JSONRPCServer(object): @@ -74,7 +75,8 @@ def write_json(self, **kwargs): It's not possible with this method to write non-objects. """ - self.stdout.write(json.dumps(kwargs) + "\n") + serialized_value = JSONEncoder().encode(kwargs) + self.stdout.write(serialized_value + "\n") self.stdout.flush() def handle_request(self): diff --git a/elpy/tests/support.py b/elpy/tests/support.py index 1e79654f3..9d7de6b37 100644 --- a/elpy/tests/support.py +++ b/elpy/tests/support.py @@ -13,15 +13,16 @@ """ import os +import pathlib +import re import shutil import sys import tempfile import unittest -import re -from elpy.tests import compat -from elpy.rpc import Fault from elpy import jedibackend +from elpy.rpc import Fault +from elpy.tests import compat class BackendTestCase(unittest.TestCase): @@ -55,7 +56,7 @@ def project_file(self, relname, contents): fobj = open(full_name, "w") with fobj as f: f.write(contents) - return full_name + return pathlib.Path(full_name) class GenericRPCTests(object): diff --git a/requirements-rpc.txt b/requirements-rpc.txt index 40e78f53c..56ba103da 100644 --- a/requirements-rpc.txt +++ b/requirements-rpc.txt @@ -1,4 +1,4 @@ -jedi==0.17.2 +jedi==0.18.0 rope==0.17.0 autopep8==1.5.4 yapf==0.30