Skip to content

fix(event_source): mypy strict mode compliance#8332

Merged
leandrodamascena merged 2 commits into
aws-powertools:developfrom
stenczelt:tks/8331-fix-event-source-typing
Jul 12, 2026
Merged

fix(event_source): mypy strict mode compliance#8332
leandrodamascena merged 2 commits into
aws-powertools:developfrom
stenczelt:tks/8331-fix-event-source-typing

Conversation

@stenczelt

Copy link
Copy Markdown
Contributor

Issue number: closes #8331

Summary

Changes

aws_lambda_powertools.utilities.data_classes.event_source complies with mypy in --strict mode as well.

Removed a redundant casting to the dataclass in examples/event_sources/src/kinesis_firehose_response_exception.py.

Changes are localised to event_source.py, rather than trying to annotate lambda_handler_decorator for all use cases, unlike earlier attempts, e.g. #4165. Since the decorator only takes the dataclass as a keyword argument, I've defined a protocol and cast the result to this.

User experience

Having a handler using the @event_source decorator, in main.py

from aws_lambda_powertools.utilities.data_classes import SQSEvent, event_source
from aws_lambda_powertools.utilities.typing import LambdaContext


@event_source(data_class=SQSEvent)
def lambda_handler(event: SQSEvent, _context: LambdaContext) -> None:
    return None

Before:

$ mypy --strict main.py

main.py:5:2: error: Untyped decorator makes function "lambda_handler" untyped  [untyped-decorator]

After:

$ mypy --strict main.py 

Success: no issues found in 1 source file

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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@stenczelt
stenczelt requested a review from a team as a code owner July 11, 2026 18:41
@stenczelt
stenczelt requested a review from hjgraca July 11, 2026 18:41
@boring-cyborg

boring-cyborg Bot commented Jul 11, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 11, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.63%. Comparing base (8a0ae64) to head (71c3f65).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
..._powertools/utilities/data_classes/event_source.py 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8332      +/-   ##
===========================================
- Coverage    96.63%   96.63%   -0.01%     
===========================================
  Files          296      296              
  Lines        14759    14764       +5     
  Branches      1243     1244       +1     
===========================================
+ Hits         14263    14267       +4     
  Misses         362      362              
- Partials       134      135       +1     

☔ View full report in Codecov by Harness.
📢 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.

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Amazing work @stenczelt! Thanks a lot, APPROVED!

@leandrodamascena
leandrodamascena merged commit a9fce32 into aws-powertools:develop Jul 12, 2026
16 of 18 checks passed
@boring-cyborg

boring-cyborg Bot commented Jul 12, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static typing: event_source makes handler untyped under mypy --strict

2 participants