Skip to content

Commit 65f798c

Browse files
committed
Adjustments to satisfy ruff and mypy
1 parent 0a88d8f commit 65f798c

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

jsonrpcserver/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ def dispatch_to_serializable(
9393
"""Takes a JSON-RPC request string and dispatches it to method(s), giving responses
9494
as dicts (or None).
9595
"""
96+
kwargs.setdefault("post_process", to_dict)
9697
return cast(
9798
Union[Dict[str, Any], List[Dict[str, Any]], None],
98-
dispatch_to_response(*args, post_process=to_dict, **kwargs),
99+
dispatch_to_response(*args, **kwargs),
99100
)
100101

101102

@@ -117,7 +118,7 @@ def dispatch_to_json(
117118
The rest: Passed through to dispatch_to_serializable.
118119
"""
119120
response = dispatch_to_serializable(*args, **kwargs)
120-
# Better to respond with the empty string instead of json "null", because "null" is
121+
# Better to respond with an empty string instead of json "null", because "null" is
121122
# an invalid JSON-RPC response.
122123
return "" if response is None else serializer(response)
123124

tests/test_dispatcher.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
TODO: Add tests for dispatch_requests (non-pure version)
44
"""
5-
from typing import Any
5+
from typing import Any, Dict
66
from unittest.mock import Mock, patch, sentinel
77
import json
88
import pytest
@@ -34,7 +34,7 @@
3434
)
3535
from jsonrpcserver.exceptions import JsonRpcError
3636
from jsonrpcserver.main import default_jsonrpc_validator
37-
from jsonrpcserver.methods import method
37+
from jsonrpcserver.methods import Method
3838
from jsonrpcserver.request import Request
3939
from jsonrpcserver.response import ErrorResponse, SuccessResponse
4040
from jsonrpcserver.result import (
@@ -47,8 +47,6 @@
4747
from jsonrpcserver.sentinels import NOCONTEXT, NODATA, NOID
4848
from jsonrpcserver.utils import identity
4949

50-
# pylint: disable=missing-function-docstring,missing-class-docstring,too-few-public-methods,unnecessary-lambda-assignment,invalid-name,disallowed-name
51-
5250

5351
def ping() -> Result:
5452
return Ok("pong")
@@ -381,7 +379,10 @@ def test_dispatch_to_response_pure_parse_error() -> None:
381379
ErrorResponse(
382380
ERROR_PARSE_ERROR,
383381
"Parse error",
384-
"Expecting property name enclosed in double quotes: line 1 column 2 (char 1)",
382+
(
383+
"Expecting property name enclosed in double quotes: "
384+
"line 1 column 2 (char 1)"
385+
),
385386
None,
386387
)
387388
)
@@ -566,14 +567,19 @@ def test_dispatch_to_response_pure_notification_parse_error() -> None:
566567
ErrorResponse(
567568
ERROR_PARSE_ERROR,
568569
"Parse error",
569-
"Expecting property name enclosed in double quotes: line 1 column 2 (char 1)",
570+
(
571+
"Expecting property name enclosed in double quotes: "
572+
"line 1 column 2 (char 1)"
573+
),
570574
None,
571575
)
572576
)
573577

574578

575579
def test_dispatch_to_response_pure_notification_invalid_request() -> None:
576-
"""Invalid JSON-RPC, must return an error. (impossible to determine if notification)"""
580+
"""Invalid JSON-RPC, must return an error. (impossible to determine if
581+
notification)
582+
"""
577583
assert dispatch_to_response_pure(
578584
validate_args,
579585
json.loads,
@@ -625,7 +631,7 @@ def foo(colour: str, size: str) -> Result: # pylint: disable=unused-argument
625631
)
626632

627633

628-
def test_dispatch_to_response_pure_invalid_params_notification_explicitly_returned() -> None:
634+
def test_dispatch_to_response_pure_invalid_params_notification_returned() -> None:
629635
def foo(colour: str) -> Result:
630636
if colour not in ("orange", "red", "yellow"):
631637
return InvalidParams()
@@ -912,7 +918,7 @@ def test_examples_mixed_requests_and_notifications() -> None:
912918
The spec example includes this which invalidates the entire request:
913919
{"foo": "boo"},
914920
"""
915-
methods = {
921+
methods: Dict[str, Method] = {
916922
"sum": lambda *args: Ok(sum(args)),
917923
"notify_hello": lambda *args: Ok(19),
918924
"subtract": lambda *args: Ok(args[0] - sum(args[1:])),
@@ -929,7 +935,12 @@ def test_examples_mixed_requests_and_notifications() -> None:
929935
{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
930936
{"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
931937
{"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},
932-
{"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},
938+
{
939+
"jsonrpc": "2.0",
940+
"method": "foo.get",
941+
"params": {"name": "myself"},
942+
"id": "5"
943+
},
933944
{"jsonrpc": "2.0", "method": "get_data", "id": "9"}
934945
]""",
935946
)

tests/test_main.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
from returns.result import Success
33

44
from jsonrpcserver.main import (
5-
default_args_validator,
6-
default_deserializer,
7-
default_jsonrpc_validator,
8-
dispatch,
95
dispatch_to_json,
106
dispatch_to_response,
11-
dispatch_to_response,
127
dispatch_to_serializable,
138
)
149
from jsonrpcserver.methods import method

0 commit comments

Comments
 (0)