Skip to content
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

Drop ujson and switch to orjson #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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