Skip to content

Commit

Permalink
Remove pylint pragmas (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcb authored Aug 17, 2024
1 parent 8c23c46 commit 1d9153e
Show file tree
Hide file tree
Showing 20 changed files with 17 additions and 48 deletions.
2 changes: 1 addition & 1 deletion examples/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def ping() -> Result:
class TestHttpServer(BaseHTTPRequestHandler):
"""HTTPServer request handler"""

def do_POST(self) -> None: # pylint: disable=invalid-name
def do_POST(self) -> None:
"""POST handler"""
# Process request
request = self.rfile.read(int(self.headers["Content-Length"])).decode()
Expand Down
6 changes: 2 additions & 4 deletions jsonrpcserver/async_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

logger = logging.getLogger(__name__)

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


async def call(
request: Request, context: Any, method: Method
Expand All @@ -49,7 +47,7 @@ async def call(
validate_result(result)
except JsonRpcError as exc:
return Failure(ErrorResult(code=exc.code, message=exc.message, data=exc.data))
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
# Other error inside method - Internal error
logger.exception(exc)
return Failure(InternalErrorResult(str(exc)))
Expand Down Expand Up @@ -139,6 +137,6 @@ async def dispatch_to_response_pure(
result.unwrap(),
)
)
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
logger.exception(exc)
return post_process(Failure(ServerErrorResponse(str(exc), None)))
2 changes: 0 additions & 2 deletions jsonrpcserver/async_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from .sentinels import NOCONTEXT
from .utils import identity

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


async def dispatch_to_response(
request: str,
Expand Down
9 changes: 4 additions & 5 deletions jsonrpcserver/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
requests, providing responses.
"""

# pylint: disable=protected-access
import logging
from functools import partial
from inspect import signature
Expand Down Expand Up @@ -143,7 +142,7 @@ def call(
except JsonRpcError as exc:
return Failure(ErrorResult(code=exc.code, message=exc.message, data=exc.data))
# Any other uncaught exception inside method - internal error.
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
logger.exception(exc)
return Failure(InternalErrorResult(str(exc)))
return result
Expand Down Expand Up @@ -249,7 +248,7 @@ def validate_request(
# Since the validator is unknown, the specific exception that will be raised is also
# unknown. Any exception raised we assume the request is invalid and return an
# "invalid request" response.
except Exception: # pylint: disable=broad-except
except Exception:
return Failure(InvalidRequestResponse("The request failed schema validation"))
return Success(request)

Expand All @@ -266,7 +265,7 @@ def deserialize_request(
# Since the deserializer is unknown, the specific exception that will be raised is
# also unknown. Any exception raised we assume the request is invalid, return a
# parse error response.
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
return Failure(ParseErrorResponse(str(exc)))


Expand Down Expand Up @@ -297,7 +296,7 @@ def dispatch_to_response_pure(
args_validator, post_process, methods, context, result.unwrap()
)
)
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
# There was an error with the jsonrpcserver library.
logging.exception(exc)
return post_process(Failure(ServerErrorResponse(str(exc), None)))
2 changes: 1 addition & 1 deletion jsonrpcserver/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def method(
f: Optional[Method] = None, # pylint: disable=invalid-name
f: Optional[Method] = None,
name: Optional[str] = None,
) -> Callable[..., Any]:
"""A decorator to add a function into jsonrpcserver's internal global_methods dict.
Expand Down
6 changes: 2 additions & 4 deletions jsonrpcserver/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ErrorResponse(NamedTuple):
Response = Result[SuccessResponse, ErrorResponse]


def ParseErrorResponse(data: Any) -> ErrorResponse: # pylint: disable=invalid-name
def ParseErrorResponse(data: Any) -> ErrorResponse:
"""An ErrorResponse with most attributes already populated.
From the spec: "This (id) member is REQUIRED. It MUST be the same as the value of
Expand All @@ -51,7 +51,7 @@ def ParseErrorResponse(data: Any) -> ErrorResponse: # pylint: disable=invalid-n
return ErrorResponse(ERROR_PARSE_ERROR, "Parse error", data, None)


def InvalidRequestResponse(data: Any) -> ErrorResponse: # pylint: disable=invalid-name
def InvalidRequestResponse(data: Any) -> ErrorResponse:
"""An ErrorResponse with most attributes already populated.
From the spec: "This (id) member is REQUIRED. It MUST be the same as the value of
Expand All @@ -63,13 +63,11 @@ def InvalidRequestResponse(data: Any) -> ErrorResponse: # pylint: disable=inval

def MethodNotFoundResponse(data: Any, id: Any) -> ErrorResponse:
"""An ErrorResponse with some attributes already populated."""
# pylint: disable=invalid-name,redefined-builtin
return ErrorResponse(ERROR_METHOD_NOT_FOUND, "Method not found", data, id)


def ServerErrorResponse(data: Any, id: Any) -> ErrorResponse:
"""An ErrorResponse with some attributes already populated."""
# pylint: disable=invalid-name,redefined-builtin
return ErrorResponse(ERROR_SERVER_ERROR, "Server error", data, id)


Expand Down
2 changes: 0 additions & 2 deletions jsonrpcserver/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
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


class SuccessResult(NamedTuple):
result: Any = None
Expand Down
1 change: 0 additions & 1 deletion jsonrpcserver/sentinels.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Sentinel:
Has a nicer repr than `object()`.
"""

# pylint: disable=too-few-public-methods
def __init__(self, name: str):
self.name = name

Expand Down
5 changes: 4 additions & 1 deletion jsonrpcserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@


class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self) -> None: # pylint: disable=invalid-name
"""Handle HTTP requests"""

def do_POST(self) -> None:
"""Handle POST request"""
request = self.rfile.read(int(str(self.headers["Content-Length"]))).decode()
response = dispatch(request)
if response is not None:
Expand Down
2 changes: 0 additions & 2 deletions jsonrpcserver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from functools import reduce
from typing import Any, Callable, List

# pylint: disable=invalid-name


def identity(x: Any) -> Any:
"""Returns the argument."""
Expand Down
2 changes: 0 additions & 2 deletions tests/test_async_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from jsonrpcserver.sentinels import NOCONTEXT, NODATA
from jsonrpcserver.utils import identity

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


async def ping() -> Result:
return Ok("pong")
Expand Down
4 changes: 0 additions & 4 deletions tests/test_async_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
from jsonrpcserver.response import SuccessResponse
from jsonrpcserver.result import Ok, Result

# pylint: disable=missing-function-docstring

# pylint: disable=missing-function-docstring


async def ping() -> Result:
return Ok("pong")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def test_dispatch_to_response_pure_method_not_found() -> None:


def test_dispatch_to_response_pure_invalid_params_auto() -> None:
def f(colour: str, size: str) -> Result: # pylint: disable=unused-argument
def f(colour: str, size: str) -> Result:
return Ok()

assert dispatch_to_response_pure(
Expand Down Expand Up @@ -615,7 +615,7 @@ def test_dispatch_to_response_pure_notification_method_not_found() -> None:


def test_dispatch_to_response_pure_notification_invalid_params_auto() -> None:
def foo(colour: str, size: str) -> Result: # pylint: disable=unused-argument
def foo(colour: str, size: str) -> Result:
return Ok()

assert (
Expand Down
6 changes: 1 addition & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
from jsonrpcserver.response import SuccessResponse
from jsonrpcserver.result import Ok, Result

# pylint: disable=missing-function-docstring

# pylint: disable=missing-function-docstring


def ping() -> Result:
return Ok("pong")
Expand All @@ -28,7 +24,7 @@ def test_dispatch_to_response() -> None:

def test_dispatch_to_response_with_global_methods() -> None:
@method
def ping() -> Result: # pylint: disable=redefined-outer-name
def ping() -> Result:
return Ok("pong")

response = dispatch_to_response('{"jsonrpc": "2.0", "method": "ping", "id": 1}')
Expand Down
2 changes: 0 additions & 2 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from jsonrpcserver.methods import global_methods, method
from jsonrpcserver.result import Ok, Result

# pylint: disable=missing-function-docstring


def test_decorator() -> None:
@method
Expand Down
2 changes: 0 additions & 2 deletions tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from jsonrpcserver.request import Request

# pylint: disable=missing-function-docstring


def test_request() -> None:
assert Request(method="foo", params=[], id=1).method == "foo"
Expand Down
2 changes: 0 additions & 2 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
to_serializable,
)

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


def test_SuccessResponse() -> None:
response = SuccessResponse(sentinel.result, sentinel.id)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
)
from jsonrpcserver.sentinels import NODATA

# pylint: disable=missing-function-docstring,invalid-name


def test_SuccessResult() -> None:
assert SuccessResult(None).result is None
Expand Down
2 changes: 0 additions & 2 deletions tests/test_sentinels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from jsonrpcserver.sentinels import Sentinel

# pylint: disable=missing-function-docstring


def test_sentinel() -> None:
assert repr(Sentinel("foo")) == "<foo>"
2 changes: 0 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from jsonrpcserver.server import serve

# pylint: disable=missing-function-docstring


@patch("jsonrpcserver.server.HTTPServer")
def test_serve(*_: Mock) -> None:
Expand Down

0 comments on commit 1d9153e

Please sign in to comment.