Skip to content

fix(parser): type hints should reflect primitive types support#8175

Merged
leandrodamascena merged 3 commits intoaws-powertools:developfrom
catarinacps:fix/parser-type-hints-accordingly
Apr 27, 2026
Merged

fix(parser): type hints should reflect primitive types support#8175
leandrodamascena merged 3 commits intoaws-powertools:developfrom
catarinacps:fix/parser-type-hints-accordingly

Conversation

@catarinacps
Copy link
Copy Markdown
Contributor

@catarinacps catarinacps commented Apr 26, 2026

Issue number: closes #8174

Summary

As per #4502, primitive types are supported by the parser utility. However, the type hints utilized in the functions and envelopes there do not reflect that at the moment, making type checkers lack when inferring the return types, for example. This aims to improve this situation by adjusting the type hints there.

Changes

Please provide a summary of what's being changed

This PR thus changes the TypeVar used in the envelope types' functions to T, introduced in #4502. It also sets the BaseEnvelope parser(...) method with envelope overload return type hint to T | list[T | None] | None to allow those subclasses to overload the method correctly.

User experience

Please share what the user experience looks like before and after this change

Before:

image

After the change the type checker will be able to narrow the type to list[EUMMessage], as that is the actual return type that should be shown.


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.

As per aws-powertools#4502, primitive types are supported by the `parser` utility. However, the type hints utilized in the functions and envelopes there do not reflect that at the moment, making type checkers lack when inferring the return types, for example. This aims to improve this situation by adjusting the type hints there.
@catarinacps catarinacps requested a review from a team as a code owner April 26, 2026 20:36
@catarinacps catarinacps requested a review from ConnorKirk April 26, 2026 20:36
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Apr 26, 2026

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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 26, 2026
@powertools-for-aws-oss-automation
Copy link
Copy Markdown

Not all issues are linked correctly.

Please link each issue to the PR either manually or using a closing keyword in the format fixes #<issue-number> format.

If mentioning more than one issue, separate them with commas: i.e. fixes #<issue-number-1>, closes #<issue-number-2>.

@catarinacps catarinacps changed the title fix: parser type hints should reflect primitive types fix: parser type hints should reflect primitive types support Apr 26, 2026
@catarinacps catarinacps changed the title fix: parser type hints should reflect primitive types support fix(parser): type hints should reflect primitive types support Apr 26, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 27, 2026
Copy link
Copy Markdown
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.

Oi @catarinacps, tudo bem? :D

This is a great contribution, clean and consistent. Swapping Model (bound to BaseModel) to unbound T across all envelopes finally makes type checkers aware of the primitive types support we added in #4502. Love it!

APROVADO!

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 27, 2026
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.72%. Comparing base (2e11129) to head (1b5d045).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8175   +/-   ##
========================================
  Coverage    96.72%   96.72%           
========================================
  Files          286      286           
  Lines        14341    14341           
  Branches      1200     1200           
========================================
  Hits         13871    13871           
  Misses         341      341           
  Partials       129      129           

☔ 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.

@leandrodamascena leandrodamascena merged commit 1585b66 into aws-powertools:develop Apr 27, 2026
17 of 18 checks passed
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented Apr 27, 2026

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

@catarinacps catarinacps deleted the fix/parser-type-hints-accordingly branch April 27, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static typing: parser utility type hints should reflect primitive types support

2 participants