Skip to content

Commit 178b632

Browse files
committed
Drop ujson and switch to orjson
Implemented as requested in this comment: python-lsp/python-lsp-server#579 (review)
1 parent 786d8dd commit 178b632

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

Diff for: examples/langserver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from pylsp_jsonrpc import dispatchers, endpoint
66

77
try:
8-
import ujson as json
9-
except Exception: # pylint: disable=broad-except
8+
import orjson as json
9+
except ImportError:
1010
import json
1111

1212
log = logging.getLogger(__name__)

Diff for: examples/langserver_ext.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from pylsp_jsonrpc import streams
88

99
try:
10-
import ujson as json
11-
except Exception: # pylint: disable=broad-except
10+
import orjson as json
11+
except ImportError:
1212
import json
1313

1414
log = logging.getLogger(__name__)

Diff for: pylsp_jsonrpc/streams.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import threading
66

77
try:
8-
import ujson as json
9-
except Exception: # pylint: disable=broad-except
8+
import orjson as json
9+
except ImportError:
1010
import json
1111

1212
log = logging.getLogger(__name__)

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [{name = "Python Language Server Contributors"}]
1111
description = "JSON RPC 2.0 server library"
1212
license = {text = "MIT"}
1313
requires-python = ">=3.8"
14-
dependencies = ["ujson>=3.0.0"]
14+
dependencies = ["orjson>=3.10.0"]
1515
dynamic = ["version"]
1616
classifiers = [
1717
"License :: OSI Approved :: MIT License",

Diff for: test/test_streams.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,20 @@ def test_reader_bad_json(rfile, reader):
7777

7878

7979
def test_writer(wfile, writer):
80-
writer.write({
80+
data = {
8181
'id': 'hello',
8282
'method': 'method',
8383
'params': {}
84-
})
85-
if 'ujson' in sys.modules:
86-
assert wfile.getvalue() == (
87-
b'Content-Length: 44\r\n'
88-
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
89-
b'\r\n'
90-
b'{"id":"hello","method":"method","params":{}}'
91-
)
92-
else:
93-
assert wfile.getvalue() == (
94-
b'Content-Length: 49\r\n'
95-
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
96-
b'\r\n'
97-
b'{"id": "hello", "method": "method", "params": {}}'
98-
)
84+
}
85+
writer.write(data)
86+
87+
raw_result = wfile.getvalue().decode()
88+
raw_result_lines = raw_result.split()
89+
90+
assert raw_result_lines[0].split(":") == "Content-Length"
91+
assert raw_result_lines[1] = 'Content-Type: application/vscode-jsonrpc; charset=utf8'
92+
assert raw_result_lines[2] = ''
93+
assert json.loads(raw_result_lines[3]) = data
9994

10095

10196
class JsonDatetime(datetime.datetime):

0 commit comments

Comments
 (0)