Skip to content

Conversation

@Iamrodos
Copy link
Contributor

@Iamrodos Iamrodos commented Jan 5, 2026

Changes

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.

This is backwards compatible since dict is a subtype of Mapping.

User experience

Before:
error: Argument of type "LambdaFunctionUrlEvent" cannot be assigned to parameter "event" of type "dict[str, Any]"
1 error, 0 warnings, 0 informations

After:
0 errors, 0 warnings, 0 informations

Validation

Test file used to validate the fix with uv run pyright test_typing_issue.py:

from typing import Any

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"}

# Test 1: Using Powertools event data class (recommended pattern from docs)
# BEFORE FIX: pyright error
# AFTER FIX: passes (0 errors)
def handler_with_event_class(event: LambdaFunctionUrlEvent, context: LambdaContext) -> dict:
    return app.resolve(event, context)

# Test 2: Using plain dict (backwards compatibility)
# BEFORE FIX: passes
# AFTER FIX: passes (dict is a subtype of Mapping)
def handler_with_dict(event: dict[str, Any], context: LambdaContext) -> dict:
    return app.resolve(event, context)

Issue number: closes #7864


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Iamrodos Iamrodos requested a review from a team as a code owner January 5, 2026 23:34
@Iamrodos Iamrodos requested a review from sdangol January 5, 2026 23:34
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jan 5, 2026
@github-actions github-actions bot added the bug Something isn't working label Jan 6, 2026
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 aws-powertools#7864
@Iamrodos Iamrodos force-pushed the fix/resolve-mapping-type-hint branch from 67bbd4d to ec2f00b Compare January 6, 2026 05:00
@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.54%. Comparing base (c553712) to head (06068a4).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #7909   +/-   ##
========================================
  Coverage    96.54%   96.54%           
========================================
  Files          275      275           
  Lines        13199    13199           
  Branches      1002     1002           
========================================
  Hits         12743    12743           
  Misses         353      353           
  Partials       103      103           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 6, 2026

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this PR @Iamrodos! APPROVED!

@leandrodamascena leandrodamascena merged commit 26f44a8 into aws-powertools:develop Jan 6, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working event_handlers size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static typing: resolve() typing should accept Mapping, not just dict

2 participants