From 1d9153e1a6a1b757fa3d118019565c91991ad581 Mon Sep 17 00:00:00 2001 From: Beau Date: Sat, 17 Aug 2024 20:40:44 +1000 Subject: [PATCH] Remove pylint pragmas (#283) --- examples/http_server.py | 2 +- jsonrpcserver/async_dispatcher.py | 6 ++---- jsonrpcserver/async_main.py | 2 -- jsonrpcserver/dispatcher.py | 9 ++++----- jsonrpcserver/methods.py | 2 +- jsonrpcserver/response.py | 6 ++---- jsonrpcserver/result.py | 2 -- jsonrpcserver/sentinels.py | 1 - jsonrpcserver/server.py | 5 ++++- jsonrpcserver/utils.py | 2 -- tests/test_async_dispatcher.py | 2 -- tests/test_async_main.py | 4 ---- tests/test_dispatcher.py | 4 ++-- tests/test_main.py | 6 +----- tests/test_methods.py | 2 -- tests/test_request.py | 2 -- tests/test_response.py | 2 -- tests/test_result.py | 2 -- tests/test_sentinels.py | 2 -- tests/test_server.py | 2 -- 20 files changed, 17 insertions(+), 48 deletions(-) diff --git a/examples/http_server.py b/examples/http_server.py index 5b81a2a..59c7bd6 100644 --- a/examples/http_server.py +++ b/examples/http_server.py @@ -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() diff --git a/jsonrpcserver/async_dispatcher.py b/jsonrpcserver/async_dispatcher.py index 49ba167..bfd47a0 100644 --- a/jsonrpcserver/async_dispatcher.py +++ b/jsonrpcserver/async_dispatcher.py @@ -36,8 +36,6 @@ logger = logging.getLogger(__name__) -# pylint: disable=missing-function-docstring,duplicate-code - async def call( request: Request, context: Any, method: Method @@ -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))) @@ -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))) diff --git a/jsonrpcserver/async_main.py b/jsonrpcserver/async_main.py index d34801c..4ff3773 100644 --- a/jsonrpcserver/async_main.py +++ b/jsonrpcserver/async_main.py @@ -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, diff --git a/jsonrpcserver/dispatcher.py b/jsonrpcserver/dispatcher.py index 2893012..467869a 100644 --- a/jsonrpcserver/dispatcher.py +++ b/jsonrpcserver/dispatcher.py @@ -2,7 +2,6 @@ requests, providing responses. """ -# pylint: disable=protected-access import logging from functools import partial from inspect import signature @@ -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 @@ -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) @@ -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))) @@ -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))) diff --git a/jsonrpcserver/methods.py b/jsonrpcserver/methods.py index c946a58..6a24930 100644 --- a/jsonrpcserver/methods.py +++ b/jsonrpcserver/methods.py @@ -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. diff --git a/jsonrpcserver/response.py b/jsonrpcserver/response.py index 3113d05..2702b0d 100644 --- a/jsonrpcserver/response.py +++ b/jsonrpcserver/response.py @@ -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 @@ -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 @@ -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) diff --git a/jsonrpcserver/result.py b/jsonrpcserver/result.py index b193880..37740c2 100644 --- a/jsonrpcserver/result.py +++ b/jsonrpcserver/result.py @@ -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 diff --git a/jsonrpcserver/sentinels.py b/jsonrpcserver/sentinels.py index 0ed0cca..46ca287 100644 --- a/jsonrpcserver/sentinels.py +++ b/jsonrpcserver/sentinels.py @@ -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 diff --git a/jsonrpcserver/server.py b/jsonrpcserver/server.py index d0c54fb..c0977c2 100644 --- a/jsonrpcserver/server.py +++ b/jsonrpcserver/server.py @@ -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: diff --git a/jsonrpcserver/utils.py b/jsonrpcserver/utils.py index a259799..ec47b32 100644 --- a/jsonrpcserver/utils.py +++ b/jsonrpcserver/utils.py @@ -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.""" diff --git a/tests/test_async_dispatcher.py b/tests/test_async_dispatcher.py index b1afbfd..78253c2 100644 --- a/tests/test_async_dispatcher.py +++ b/tests/test_async_dispatcher.py @@ -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") diff --git a/tests/test_async_main.py b/tests/test_async_main.py index 7686a8e..f70e83f 100644 --- a/tests/test_async_main.py +++ b/tests/test_async_main.py @@ -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") diff --git a/tests/test_dispatcher.py b/tests/test_dispatcher.py index 26fe49a..a58885a 100644 --- a/tests/test_dispatcher.py +++ b/tests/test_dispatcher.py @@ -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( @@ -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 ( diff --git a/tests/test_main.py b/tests/test_main.py index fae47ce..52c936b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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") @@ -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}') diff --git a/tests/test_methods.py b/tests/test_methods.py index 4459e7a..901b781 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -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 diff --git a/tests/test_request.py b/tests/test_request.py index 67e803b..728cc9a 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -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" diff --git a/tests/test_response.py b/tests/test_response.py index 7829349..a0da382 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -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) diff --git a/tests/test_result.py b/tests/test_result.py index 797263c..3cb2f9b 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -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 diff --git a/tests/test_sentinels.py b/tests/test_sentinels.py index b1e5ffe..555460a 100644 --- a/tests/test_sentinels.py +++ b/tests/test_sentinels.py @@ -2,8 +2,6 @@ from jsonrpcserver.sentinels import Sentinel -# pylint: disable=missing-function-docstring - def test_sentinel() -> None: assert repr(Sentinel("foo")) == "" diff --git a/tests/test_server.py b/tests/test_server.py index 46c2b51..94753cf 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -4,8 +4,6 @@ from jsonrpcserver.server import serve -# pylint: disable=missing-function-docstring - @patch("jsonrpcserver.server.HTTPServer") def test_serve(*_: Mock) -> None: