Skip to content

Commit

Permalink
Drop ujson and switch to orjson
Browse files Browse the repository at this point in the history
Implemented as requested in this comment:
python-lsp/python-lsp-server#579 (review)
  • Loading branch information
rumpelsepp committed Jul 30, 2024
1 parent 786d8dd commit 178b632
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from pylsp_jsonrpc import dispatchers, endpoint

try:
import ujson as json
except Exception: # pylint: disable=broad-except
import orjson as json
except ImportError:
import json

log = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions examples/langserver_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pylsp_jsonrpc import streams

try:
import ujson as json
except Exception: # pylint: disable=broad-except
import orjson as json
except ImportError:
import json

log = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions pylsp_jsonrpc/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import threading

try:
import ujson as json
except Exception: # pylint: disable=broad-except
import orjson as json
except ImportError:
import json

log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [{name = "Python Language Server Contributors"}]
description = "JSON RPC 2.0 server library"
license = {text = "MIT"}
requires-python = ">=3.8"
dependencies = ["ujson>=3.0.0"]
dependencies = ["orjson>=3.10.0"]
dynamic = ["version"]
classifiers = [
"License :: OSI Approved :: MIT License",
Expand Down
27 changes: 11 additions & 16 deletions test/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,20 @@ def test_reader_bad_json(rfile, reader):


def test_writer(wfile, writer):
writer.write({
data = {
'id': 'hello',
'method': 'method',
'params': {}
})
if 'ujson' in sys.modules:
assert wfile.getvalue() == (
b'Content-Length: 44\r\n'
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
b'\r\n'
b'{"id":"hello","method":"method","params":{}}'
)
else:
assert wfile.getvalue() == (
b'Content-Length: 49\r\n'
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
b'\r\n'
b'{"id": "hello", "method": "method", "params": {}}'
)
}
writer.write(data)

raw_result = wfile.getvalue().decode()
raw_result_lines = raw_result.split()

assert raw_result_lines[0].split(":") == "Content-Length"
assert raw_result_lines[1] = 'Content-Type: application/vscode-jsonrpc; charset=utf8'
assert raw_result_lines[2] = ''
assert json.loads(raw_result_lines[3]) = data


class JsonDatetime(datetime.datetime):
Expand Down

0 comments on commit 178b632

Please sign in to comment.