diff --git a/aws_lambda_powertools/event_handler/api_gateway.py b/aws_lambda_powertools/event_handler/api_gateway.py index 0f45cccb5b1..001fcceac72 100644 --- a/aws_lambda_powertools/event_handler/api_gateway.py +++ b/aws_lambda_powertools/event_handler/api_gateway.py @@ -83,6 +83,7 @@ TypeModelOrEnum, ) from aws_lambda_powertools.shared.cookies import Cookie + from aws_lambda_powertools.shared.types import AnyCallableT from aws_lambda_powertools.utilities.typing import LambdaContext @@ -924,7 +925,7 @@ def route( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: raise NotImplementedError() def use(self, middlewares: list[Callable[..., Response]]) -> None: @@ -984,7 +985,7 @@ def get( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: """Get route decorator with GET `method` Examples @@ -1041,7 +1042,7 @@ def post( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: """Post route decorator with POST `method` Examples @@ -1099,7 +1100,7 @@ def put( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: """Put route decorator with PUT `method` Examples @@ -1157,7 +1158,7 @@ def delete( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: """Delete route decorator with DELETE `method` Examples @@ -1214,7 +1215,7 @@ def patch( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: """Patch route decorator with PATCH `method` Examples @@ -1274,7 +1275,7 @@ def head( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: """Head route decorator with HEAD `method` Examples @@ -1950,10 +1951,10 @@ def route( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: """Route decorator includes parameter `method`""" - def register_resolver(func: Callable): + def register_resolver(func: AnyCallableT) -> AnyCallableT: methods = (method,) if isinstance(method, str) else method logger.debug(f"Adding route using rule {rule} and methods: {','.join(m.upper() for m in methods)}") @@ -2492,8 +2493,8 @@ def route( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): - def register_route(func: Callable): + ) -> Callable[[AnyCallableT], AnyCallableT]: + def register_route(func: AnyCallableT) -> AnyCallableT: # All dict keys needs to be hashable. So we'll need to do some conversions: methods = (method,) if isinstance(method, str) else tuple(method) frozen_responses = _FrozenDict(responses) if responses else None @@ -2598,7 +2599,7 @@ def route( security: list[dict[str, list[str]]] | None = None, openapi_extensions: dict[str, Any] | None = None, middlewares: list[Callable[..., Any]] | None = None, - ): + ) -> Callable[[AnyCallableT], AnyCallableT]: # NOTE: see #1552 for more context. return super().route( rule.rstrip("/"),