Static type checker used
pyright/pylance
AWS Lambda function runtime
3.14
Powertools for AWS Lambda (Python) version
latest
Static type checker info
uv run pyright example.py
Argument of type "LambdaFunctionUrlEvent" cannot be assigned to parameter "event" of type "dict[str, Any]"
Code snippet
from aws_lambda_powertools.event_handler import LambdaFunctionUrlResolver
from aws_lambda_powertools.utilities.data_classes import LambdaFunctionUrlEvent
from aws_lambda_powertools.utilities.typing import LambdaContext
app = LambdaFunctionUrlResolver()
@app.get("/")
def home():
return {"message": "Hello"}
# This is the recommended typed handler signature from Powertools docs
def handler(event: LambdaFunctionUrlEvent, context: LambdaContext) -> dict:
# ERROR: Argument of type "LambdaFunctionUrlEvent" cannot be assigned
# to parameter "event" of type "dict[str, Any]"
return app.resolve(event, context)
Possible Solution
straightforward and backwards-compatible:
in aws_lambda_powertools/event_handler/api_gateway.py
From:
def resolve(self, event: dict[str, Any], context: LambdaContext) -> dict[str, Any]:
To:
from collections.abc import Mapping
def resolve(self, event: Mapping[str, Any], context: LambdaContext) -> dict[str, Any]:
This works because dict is a subtype of Mapping, and resolve() only reads from the event, never mutates it
Happy to do a PR for this.
Static type checker used
pyright/pylance
AWS Lambda function runtime
3.14
Powertools for AWS Lambda (Python) version
latest
Static type checker info
uv run pyright example.py
Code snippet
Possible Solution
straightforward and backwards-compatible:
in
aws_lambda_powertools/event_handler/api_gateway.pyFrom:
def resolve(self, event: dict[str, Any], context: LambdaContext) -> dict[str, Any]:To:
This works because dict is a subtype of Mapping, and resolve() only reads from the event, never mutates it
Happy to do a PR for this.