Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0f1fd29
Replace Oslash with Returns
bcb May 14, 2022
c1426f6
Fix github action
bcb May 14, 2022
d806553
Fix github action
bcb May 14, 2022
0ede79e
Add comment to docs
bcb May 17, 2022
9451357
Merge branch 'use-returns' into prepare-v6
bcb May 18, 2022
a854670
Prepare version 6.0.0
bcb May 18, 2022
e9c2da2
Merge branch 'main' into prepare-v6
bcb May 19, 2022
8808a43
Adjust docstring
bcb May 20, 2022
03f80d0
Remove errant comma
bcb May 24, 2022
173bbca
Merge branch 'main' into release/6.0.0
bcb Sep 21, 2022
609b990
Adjust github workflow
bcb Sep 21, 2022
bae441c
Upgrade mypy in github workflow
bcb Sep 21, 2022
866a4e2
Enable all Pylint errors
bcb Oct 10, 2022
e74da97
Merge branch 'main' into release/6.0.0
bcb Oct 10, 2022
f6294ee
Fix not re-exported error
bcb Oct 10, 2022
ab30150
Upgrade pylint
bcb Nov 9, 2022
4f510b1
Pylint fixes
bcb Nov 9, 2022
73ba6a3
Update changelog
bcb Nov 9, 2022
0e67522
Fix some tests
bcb Nov 16, 2022
f4e8761
Fix parameters
bcb Feb 26, 2023
558215b
Fixes to satisfy ruff
bcb Feb 26, 2023
0a88d8f
Replace pylint with ruff
bcb Mar 3, 2023
65f798c
Adjustments to satisfy ruff and mypy
bcb Mar 3, 2023
843fdcd
Fix a repr
bcb May 10, 2023
ae90cdf
Use ruff in github actions
bcb May 10, 2023
6db0f90
Fix type error
bcb May 10, 2023
e7287b5
Upgrade ruff
bcb May 10, 2023
75cee0e
Replace setup.py with pyproject.toml
bcb May 24, 2023
9a1fe9f
Always stop the server when exiting serve()
bcb May 31, 2023
ffe8374
Replace black and isort with ruff (#278)
bcb Jul 29, 2024
be34675
Move documentation to Github wiki (#280)
bcb Jul 31, 2024
389959d
Update readme (#281)
bcb Jul 31, 2024
8c23c46
Replace readthedocs with mkdocs (#282)
bcb Aug 16, 2024
1d9153e
Remove pylint pragmas (#283)
bcb Aug 17, 2024
6efc172
Move request-schema.json to a .py file (#284)
bcb Aug 28, 2024
5c745ce
Add jsonschema dependency
bcb Nov 14, 2024
c2b807e
Add license badge
bcb Mar 22, 2025
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
Prev Previous commit
Next Next commit
Pylint fixes
  • Loading branch information
bcb committed Nov 9, 2022
commit 4f510b1be877988ae82c50e81d602fa4fdc2bbb0
2 changes: 1 addition & 1 deletion examples/fastapi_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""FastAPI server"""
from fastapi import FastAPI, Request, Response
from jsonrpcserver import dispatch, method, Ok, Result
import uvicorn # type: ignore
from jsonrpcserver import dispatch, method, Ok, Result

app = FastAPI()

Expand Down
13 changes: 7 additions & 6 deletions jsonrpcserver/async_methods.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Async methods"""
from typing import Any, Awaitable, Callable, Dict, Optional, cast

from returns.result import Result
Expand All @@ -6,11 +7,11 @@

Method = Callable[..., Awaitable[Result[SuccessResult, ErrorResult]]]
Methods = Dict[str, Method]
global_methods: Methods = dict()
global_methods: Methods = {}


def method(
f: Optional[Method] = None, name: Optional[str] = None
func: Optional[Method] = None, name: Optional[str] = None
) -> Callable[..., Awaitable[Any]]:
"""A decorator to add a function into jsonrpcserver's internal global_methods dict.
The global_methods dict will be used by default unless a methods argument is passed
Expand All @@ -23,9 +24,9 @@ def foo():
...
"""

def decorator(func: Method) -> Method:
def decorator(func_: Method) -> Method:
nonlocal name
global_methods[name or func.__name__] = func
return func
global_methods[name or func_.__name__] = func_
return func_

return decorator(f) if callable(f) else cast(Method, decorator)
return decorator(func) if callable(func) else cast(Method, decorator)
8 changes: 4 additions & 4 deletions tests/test_async_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ async def test_dispatch_to_response_pure_success() -> None:
@patch("jsonrpcserver.async_dispatcher.dispatch_request", side_effect=ValueError("foo"))
@pytest.mark.asyncio
async def test_dispatch_to_response_pure_server_error(_: Mock) -> None:
async def foo() -> Result:
async def ping() -> Result:
return Ok()

assert await dispatch_to_response_pure(
deserializer=default_deserializer,
validator=default_validator,
post_process=identity,
context=NOCONTEXT,
methods={"foo": foo},
request='{"jsonrpc": "2.0", "method": "foo", "id": 1}',
) == Failure(ErrorResponse(ERROR_SERVER_ERROR, "Server error", "foo", None))
methods={"ping": ping},
request='{"jsonrpc": "2.0", "method": "ping", "id": 1}',
) == Failure(ErrorResponse(ERROR_SERVER_ERROR, "Server error", "ping", None))
8 changes: 4 additions & 4 deletions tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

TODO: Add tests for dispatch_requests (non-pure version)
"""
from typing import Any, Callable, Dict
from typing import Any
from unittest.mock import Mock, patch, sentinel
import json
import pytest
Expand Down Expand Up @@ -167,14 +167,14 @@ def f() -> Result:


def test_validate_result_positionals() -> None:
def f(x: int) -> Result:
def f(_: int) -> Result:
return Ok()

assert validate_args(Request("f", [1], NOID), NOCONTEXT, f) == Success(f)


def test_validate_result_positionals_not_passed() -> None:
def f(x: str) -> Result:
def f(_: str) -> Result:
return Ok()

assert validate_args(Request("f", {"foo": "bar"}, NOID), NOCONTEXT, f) == Failure(
Expand All @@ -185,7 +185,7 @@ def f(x: str) -> Result:


def test_validate_result_keywords() -> None:
def f(**kwargs: str) -> Result:
def f(**_: str) -> Result:
return Ok()

assert validate_args(Request("f", {"foo": "bar"}, NOID), NOCONTEXT, f) == Success(f)
Expand Down