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
Replace black and isort with ruff (#278)
Closes #277
  • Loading branch information
bcb authored Jul 29, 2024
commit ffe83747769c33660aa5b3323ac0b31435301685
4 changes: 2 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
python-version: 3.8
- run: pip install --upgrade pip
- run: pip install types-setuptools "black<23" ruff "mypy<2" "jsonschema<5" pytest "returns<1" "aiohttp<4" "aiozmq<1" "django<5" "fastapi<1" "flask<3" "flask-socketio<5.3.1" "pyzmq" "sanic" "tornado<7" "uvicorn<1" "websockets<11"
- run: black --diff --check $(git ls-files -- '*.py' ':!:docs/*')
- run: ruff $(git ls-files -- '*.py' ':!:docs/*')
- run: ruff check --select I $(git ls-files -- '*.py' ':!:docs/*')
- run: ruff format --check $(git ls-files -- '*.py' ':!:docs/*')
- run: mypy --strict $(git ls-files -- '*.py' ':!:docs/*')
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ default_language_version:
exclude: (^docs)
fail_fast: true
repos:
- repo: https://github.com/ambv/black
rev: 22.8.0
hooks:
- id: black
args: [--diff, --check]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.265
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
hooks:
- id: ruff
name: lint with ruff
- id: ruff
name: sort imports with ruff
args: [--select, I, --fix]
- id: ruff-format
name: format with ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
from typing import List

# -- Path setup --------------------------------------------------------------

Expand Down Expand Up @@ -38,7 +39,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
exclude_patterns: List[str] = []


# -- Options for HTML output -------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion examples/aiohttp_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""AioHTTP server"""

from aiohttp import web
from jsonrpcserver import async_dispatch, async_method, Ok, Result

from jsonrpcserver import Ok, Result, async_dispatch, async_method


@async_method
Expand Down
4 changes: 3 additions & 1 deletion examples/aiozmq_server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""AioZMQ server"""

import asyncio

import aiozmq # type: ignore
import zmq
from jsonrpcserver import async_dispatch, async_method, Ok, Result

from jsonrpcserver import Ok, Result, async_dispatch, async_method


@async_method
Expand Down
3 changes: 2 additions & 1 deletion examples/asyncio_server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Demonstrates processing a batch of 100 requests asynchronously with asyncio."""

import asyncio
import json

from jsonrpcserver import async_dispatch, async_method, Ok, Result
from jsonrpcserver import Ok, Result, async_dispatch, async_method


@async_method
Expand Down
4 changes: 3 additions & 1 deletion examples/django_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Django server"""

from django.http import HttpRequest, HttpResponse # type: ignore
from django.views.decorators.csrf import csrf_exempt # type: ignore
from jsonrpcserver import dispatch, method, Ok, Result

from jsonrpcserver import Ok, Result, dispatch, method


@method
Expand Down
6 changes: 4 additions & 2 deletions examples/fastapi_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""FastAPI server"""
from fastapi import FastAPI, Request, Response

import uvicorn
from jsonrpcserver import dispatch, method, Ok, Result
from fastapi import FastAPI, Request, Response

from jsonrpcserver import Ok, Result, dispatch, method

app = FastAPI()

Expand Down
4 changes: 3 additions & 1 deletion examples/flask_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Flask server"""

from flask import Flask, Response, request
from jsonrpcserver import dispatch, method, Ok, Result

from jsonrpcserver import Ok, Result, dispatch, method

app = Flask(__name__)

Expand Down
3 changes: 2 additions & 1 deletion examples/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Demonstrates using Python's builtin http.server module to serve JSON-RPC.
"""

from http.server import BaseHTTPRequestHandler, HTTPServer

from jsonrpcserver import dispatch, method, Ok, Result
from jsonrpcserver import Ok, Result, dispatch, method


@method
Expand Down
3 changes: 2 additions & 1 deletion examples/jsonrpcserver_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Uses jsonrpcserver's built-in "serve" function.
"""
from jsonrpcserver import method, serve, Ok, Result

from jsonrpcserver import Ok, Result, method, serve


@method
Expand Down
4 changes: 3 additions & 1 deletion examples/sanic_server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Sanic server"""

from sanic import Sanic
from sanic.request import Request
from sanic.response import HTTPResponse, json
from jsonrpcserver import dispatch_to_serializable, method, Ok, Result

from jsonrpcserver import Ok, Result, dispatch_to_serializable, method

app = Sanic("JSON-RPC app")

Expand Down
4 changes: 3 additions & 1 deletion examples/socketio_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""SocketIO server"""

from flask import Flask, Request
from flask_socketio import SocketIO, send # type: ignore
from jsonrpcserver import dispatch, method, Ok, Result

from jsonrpcserver import Ok, Result, dispatch, method

app = Flask(__name__)
socketio = SocketIO(app)
Expand Down
4 changes: 3 additions & 1 deletion examples/tornado_server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tornado server"""

from typing import Awaitable, Optional

from tornado import ioloop, web
from jsonrpcserver import async_dispatch, async_method, Ok, Result

from jsonrpcserver import Ok, Result, async_dispatch, async_method


@async_method
Expand Down
4 changes: 3 additions & 1 deletion examples/websockets_server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Websockets server"""

import asyncio

from websockets.server import WebSocketServerProtocol, serve
from jsonrpcserver import async_dispatch, async_method, Ok, Result

from jsonrpcserver import Ok, Result, async_dispatch, async_method


@async_method
Expand Down
4 changes: 3 additions & 1 deletion examples/werkzeug_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Werkzeug server"""

from werkzeug.serving import run_simple
from werkzeug.wrappers import Request, Response
from jsonrpcserver import method, Result, Ok, dispatch

from jsonrpcserver import Ok, Result, dispatch, method


@method
Expand Down
4 changes: 3 additions & 1 deletion examples/zeromq_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""ZeroMQ server"""

import zmq
from jsonrpcserver import dispatch, method, Ok, Result

from jsonrpcserver import Ok, Result, dispatch, method

socket = zmq.Context().socket(zmq.REP)

Expand Down
5 changes: 5 additions & 0 deletions jsonrpcserver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
"""Jsonrpcserver"""

from returns.result import Result as R

from .async_main import (
dispatch as async_dispatch,
)
from .async_main import (
dispatch_to_response as async_dispatch_to_response,
)
from .async_main import (
dispatch_to_serializable as async_dispatch_to_serializable,
)
from .async_methods import method as async_method
Expand Down
9 changes: 5 additions & 4 deletions jsonrpcserver/async_dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Async version of dispatcher.py"""

import asyncio
import logging
from functools import partial
from inspect import signature
from itertools import starmap
from typing import Any, Callable, Iterable, Tuple, Union
import asyncio
import logging

from returns.result import Failure, Result, Success

from .async_methods import Method, Methods
from .dispatcher import (
Deserialized,
create_request,
Expand All @@ -21,16 +23,15 @@
validate_result,
)
from .exceptions import JsonRpcError
from .async_methods import Method, Methods
from .request import Request
from .response import Response, ServerErrorResponse
from .result import (
ErrorResult,
InternalErrorResult,
InvalidParamsResult,
MethodNotFoundResult,
SuccessResult,
)
from .response import Response, ServerErrorResponse
from .utils import make_list

logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions jsonrpcserver/async_main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Async version of main.py. The public async functions."""

import json
from typing import Any, Callable, Dict, Iterable, List, Optional, Union, cast

from .async_dispatcher import dispatch_to_response_pure
from .async_methods import Methods, global_methods
from .dispatcher import Deserialized
from .main import default_jsonrpc_validator, default_deserializer
from .main import default_deserializer, default_jsonrpc_validator
from .response import Response, to_serializable
from .sentinels import NOCONTEXT
from .utils import identity


# pylint: disable=missing-function-docstring,duplicate-code


Expand Down
1 change: 1 addition & 0 deletions jsonrpcserver/async_methods.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async methods"""

from typing import Any, Awaitable, Callable, Dict, Optional, cast

from returns.result import Result
Expand Down
7 changes: 4 additions & 3 deletions jsonrpcserver/dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
"""Dispatcher - does the hard work of this library: parses, validates and dispatches
requests, providing responses.
"""

# pylint: disable=protected-access
import logging
from functools import partial
from inspect import signature
from itertools import starmap
from typing import Any, Callable, Dict, Iterable, List, Tuple, Union
import logging

from returns.result import Result, Failure, Success
from returns.result import Failure, Result, Success

from .exceptions import JsonRpcError
from .methods import Method, Methods
from .request import Request
from .response import (
Response,
ErrorResponse,
InvalidRequestResponse,
ParseErrorResponse,
Response,
ServerErrorResponse,
SuccessResponse,
)
Expand Down
2 changes: 2 additions & 0 deletions jsonrpcserver/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Exceptions"""

from typing import Any

from .sentinels import NODATA


Expand Down
4 changes: 2 additions & 2 deletions jsonrpcserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
- dispatch_to_json/dispatch: Returns a JSON-RPC response string (or an empty string for
notifications).
"""

import json
from importlib.resources import read_text
from typing import Any, Callable, Dict, List, Union, cast
import json

from jsonschema.validators import validator_for # type: ignore

Expand All @@ -26,7 +27,6 @@
from .sentinels import NOCONTEXT
from .utils import identity


default_args_validator = validate_args
default_deserializer = json.loads

Expand Down
1 change: 1 addition & 0 deletions jsonrpcserver/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Methods can take either positional or named arguments, but not both. This is a
limitation of JSON-RPC.
"""

from typing import Any, Callable, Dict, Optional, cast

from returns.result import Result
Expand Down
1 change: 1 addition & 0 deletions jsonrpcserver/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
After parsing a request string, we put the (dict) requests into these Request
namedtuples, simply because they're nicer to work with.
"""

from typing import Any, Dict, List, NamedTuple, Union


Expand Down
5 changes: 3 additions & 2 deletions jsonrpcserver/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

https://www.jsonrpc.org/specification#response_object
"""

from typing import Any, Dict, List, NamedTuple, Union

from returns.result import Result, Failure
from returns.result import Failure, Result

from .codes import (
ERROR_INVALID_REQUEST,
Expand Down Expand Up @@ -101,7 +102,7 @@ def to_dict(response: Response) -> Dict[str, Any]:


def to_serializable(
response: Union[Response, List[Response], None]
response: Union[Response, List[Response], None],
) -> Union[Deserialized, None]:
"""Serialize a response object (or list of them), to a dict, or list of them."""
if response is None:
Expand Down
6 changes: 4 additions & 2 deletions jsonrpcserver/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

The public functions are Success, Error and InvalidParams.
"""

from typing import Any, NamedTuple

from returns.result import Failure, Result as R, Success
from returns.result import Failure, Success
from returns.result import Result as R

from .codes import ERROR_INVALID_PARAMS, ERROR_METHOD_NOT_FOUND, ERROR_INTERNAL_ERROR
from .codes import ERROR_INTERNAL_ERROR, ERROR_INVALID_PARAMS, ERROR_METHOD_NOT_FOUND
from .sentinels import NODATA

# pylint: disable=missing-class-docstring,missing-function-docstring,invalid-name
Expand Down
Loading