Skip to content

Commit ec2f00b

Browse files
committed
fix(typing): accept Mapping type in resolve() for event parameter
Change resolve() event parameter type hint from dict[str, Any] to Mapping[str, Any] to allow Powertools event data classes (e.g., LambdaFunctionUrlEvent) to be passed without type errors. Use cast(dict, event) for internal method calls that expect dict type to satisfy mypy while maintaining zero runtime overhead. This is backwards compatible since dict is a subtype of Mapping. Closes #7864
1 parent 896c0ee commit ec2f00b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,7 @@ def register_resolver(func: AnyCallableT) -> AnyCallableT:
24612461

24622462
return register_resolver
24632463

2464-
def resolve(self, event: dict[str, Any], context: LambdaContext) -> dict[str, Any]:
2464+
def resolve(self, event: Mapping[str, Any], context: LambdaContext) -> dict[str, Any]:
24652465
"""Resolves the response based on the provide event and decorator routes
24662466
24672467
## Internals
@@ -2514,10 +2514,10 @@ def resolve(self, event: dict[str, Any], context: LambdaContext) -> dict[str, An
25142514
event = event.raw_event
25152515

25162516
if self._debug:
2517-
print(self._serializer(event))
2517+
print(self._serializer(cast(dict, event)))
25182518

25192519
# Populate router(s) dependencies without keeping a reference to each registered router
2520-
BaseRouter.current_event = self._to_proxy_event(event)
2520+
BaseRouter.current_event = self._to_proxy_event(cast(dict, event))
25212521
BaseRouter.lambda_context = context
25222522

25232523
response = self._resolve().build(self.current_event, self._cors)

0 commit comments

Comments
 (0)