From a8ce1f03a11004c084698fe6652cefe25d4c4444 Mon Sep 17 00:00:00 2001 From: Adham Salama Date: Thu, 20 Apr 2023 01:50:09 +0200 Subject: [PATCH 1/3] Remove handler return type hint --- simpleapi/handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/simpleapi/handler.py b/simpleapi/handler.py index a63e5f9..152e75a 100644 --- a/simpleapi/handler.py +++ b/simpleapi/handler.py @@ -51,6 +51,10 @@ def handle_request( return middleware_response handler_type_hints = get_type_hints(handler["handler"]) + # Remove return type hint as we don't need it because it had caused + # a validation error for any handler function that had a return type hint + if "return" in handler_type_hints: + del handler_type_hints["return"] dependency_injection: dict[str, Any] = {} for k, v in handler_type_hints.items(): if v == Request: From 97b86acdc09413bde40926c8a503704e9d38d06a Mon Sep 17 00:00:00 2001 From: Adham Salama Date: Thu, 20 Apr 2023 01:50:40 +0200 Subject: [PATCH 2/3] Add return type hint as a test --- tests/app.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/app.py b/tests/app.py index 015e7eb..5a1326f 100644 --- a/tests/app.py +++ b/tests/app.py @@ -24,7 +24,10 @@ def always_reject_middleware(request: Request): @app.get("/set-cookie") -def set_cookies(request: Request): +# Don't remove the return type hint +# this catches the case where handler function +# has return type hint which throw a validation error +def set_cookies(request: Request) -> JSONResponse: """Sets cookies""" res = JSONResponse(body=request.cookies, headers=[("header1", "value1")]) res.set_cookie("key1", "value1") From 56945001bd12faebcbfbbfbbf08fe2b3523d84f1 Mon Sep 17 00:00:00 2001 From: Adham Salama Date: Thu, 20 Apr 2023 01:53:38 +0200 Subject: [PATCH 3/3] Bump version --- pyproject.toml | 2 +- simpleapi/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 93abb34..67f2d3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "simplestapi" -version = "0.1.4" +version = "0.1.5" description = "SimpleAPI is a minimalistic, unopinionated web framework for Python, inspired by FastAPI & Flask" authors = ["Adham Salama "] license = "MIT" diff --git a/simpleapi/__init__.py b/simpleapi/__init__.py index 5297e1f..5cd8364 100644 --- a/simpleapi/__init__.py +++ b/simpleapi/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.2" +__version__ = "0.1.5" from .custom_types import RouteHandler, ViewFunction, Middleware, Query from .request import Request