Skip to content

Commit

Permalink
chore: run mypy in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclimse committed Feb 28, 2023
1 parent d06422f commit 09f22fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ profile = "black"

[tool.mypy]
python_version = "3.8"
warn_return_any = true
warn_unused_configs = true
check_untyped_defs = true
strict = true
exclude = ['^tests\.*']

[tool.pydocstyle]
# Compatible with Sphinx
Expand Down
4 changes: 2 additions & 2 deletions scaleway_functions_python/testing/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..framework.v1.hints import Event


def inject_ingress_headers(request: "Request", event: "Event"):
def inject_ingress_headers(request: "Request", event: "Event") -> None:
"""Inject headers for incoming requests.
..note::
Expand All @@ -33,6 +33,6 @@ def inject_ingress_headers(request: "Request", event: "Event"):
event["headers"].update(**headers)


def inject_egress_headers(response: "Response"):
def inject_egress_headers(response: "Response") -> None:
"""Inject headers for outgoing requests."""
response.headers.add("server", "envoy")
18 changes: 11 additions & 7 deletions scaleway_functions_python/testing/serving.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from base64 import b64decode
from json import JSONDecodeError
from typing import TYPE_CHECKING, ClassVar, cast
from typing import TYPE_CHECKING, Any, ClassVar, cast

from flask import Flask, json, jsonify, make_response, request
from flask.views import View
Expand Down Expand Up @@ -32,7 +32,7 @@
MAX_CONTENT_LENGTH = 6291456


class HandlerWrapper(View):
class HandlerWrapper(View): # type: ignore # Subclass of untyped class
"""View that emulates the provider-side processing of requests."""

init_every_request: ClassVar[bool] = False
Expand All @@ -45,7 +45,7 @@ def logger(self) -> "logging.Logger":
"""Utility function to get a logger."""
return logging.getLogger(self.handler.__name__)

def dispatch_request(self, *_args, **_kwargs):
def dispatch_request(self, *_args: Any, **_kwargs: Any) -> "FlaskResponse":
"""Handle http requests."""
self.emulate_core_preprocess(request)

Expand All @@ -62,13 +62,13 @@ def dispatch_request(self, *_args, **_kwargs):

return resp

def emulate_core_preprocess(self, req: "FlaskRequest"):
def emulate_core_preprocess(self, req: "FlaskRequest") -> None:
"""Emulate the CoreRT guard."""
if req.content_length and req.content_length > MAX_CONTENT_LENGTH:
self.logger.warning(
"Request is too big, should not exceed %s Mb but is %s Mb",
MAX_CONTENT_LENGTH / (1 << 20),
request.content_length / (1 << 20), # type: ignore
request.content_length / (1 << 20),
)
if req.path in ["/favicon.ico", "/robots.txt"]:
self.logger.warning(
Expand Down Expand Up @@ -158,8 +158,12 @@ def _create_flask_app(handler: "hints.Handler") -> Flask:


def serve_handler_locally(
handler: "hints.Handler", *args, port: int = 8080, debug: bool = True, **kwargs
):
handler: "hints.Handler",
*args: Any,
port: int = 8080,
debug: bool = True,
**kwargs: Any,
) -> None:
"""Serve a single FaaS handler on a local http server.
:param handler: serverless python handler
Expand Down

0 comments on commit 09f22fb

Please sign in to comment.