-
Notifications
You must be signed in to change notification settings - Fork 441
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationmiddleware_factoryMiddleware factory utilityMiddleware factory utility
Description
What were you searching in the docs?
All examples on the middleware factory page present a middleware function with return type of Callable
which seems incorrect.

The actual return type of the middleware_before
function is the same as the one of the lambda handler - dict
this case. Only after the function is decorated, it'll be a Callable
but I believe the function definition should anyway have the return type of dict
.
A small reproducible example:
from typing import Callable
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
LambdaHandler = Callable[[dict, dict], dict]
@lambda_handler_decorator
def middleware_add_headers(
handler: LambdaHandler, event: dict, context: dict
) -> Callable:
return handler(event, context)
@middleware_add_headers
def lambda_handler(event: dict, context: dict) -> dict:
return {
"statusCode": 200,
"body": "hello",
}
Mypy output:
$ mypy main.py
handler.py:12: error: Incompatible return value type (got "dict[Any, Any]", expected "Callable[..., Any]") [return-value]
Found 1 error in 1 file (checked 1 source file)
Is this related to an existing documentation section?
How can we improve?
All invalid examples should be updated with correct return types (seems like dict
in all cases).
Got a suggestion in mind?
I'm happy to help with resolving this issue.
Acknowledgment
- I understand the final update might be different from my proposed suggestion, or refused.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationmiddleware_factoryMiddleware factory utilityMiddleware factory utility
Type
Projects
Status
Shipped