Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(event_handler): add type annotations for router decorators #5601

Merged

Conversation

rafrafek
Copy link
Contributor

@rafrafek rafrafek commented Nov 20, 2024

Issue number: #3990

Summary

Adds type annotations for Api Gateway Router decorators to improve Pyright compatibility. Fixes Pyright error Untyped function decorator obscures type of function when used in "strict" type checking mode. May be helpful especially for VS Code users.

Changes

  • Added type annotations for the return value of Api Gateway Router decorators.

User experience

  • Before the change the decorators were showing errors in VS Code when Pylance/Pyright was set to "strict" mode.
  • Now there are no errors

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 20, 2024
@rafrafek rafrafek changed the title Fixed type annotation for Api Gateway Router fix(router): add type annotations for Api Gateway Router decorators to resolve Pyright errors Nov 20, 2024
@rafrafek rafrafek changed the title fix(router): add type annotations for Api Gateway Router decorators to resolve Pyright errors chore(router): add type annotations for Api Gateway Router decorators to improve Pyright compatibility Nov 20, 2024
@rafrafek rafrafek marked this pull request as ready for review November 20, 2024 15:45
@rafrafek rafrafek requested a review from a team November 20, 2024 15:45
@rafrafek
Copy link
Contributor Author

Should I use AnyCallableT from aws_lambda_powertools/shared/types.py?

@github-actions github-actions bot added bug Something isn't working internal Maintenance changes labels Nov 20, 2024
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.14%. Comparing base (811da57) to head (6470d2e).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5601   +/-   ##
========================================
  Coverage    96.14%   96.14%           
========================================
  Files          229      229           
  Lines        10854    10854           
  Branches      2018     2018           
========================================
  Hits         10436    10436           
  Misses         329      329           
  Partials        89       89           

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


🚨 Try these New Features:

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.

Hey @rafrafek! Thanks for sending this PR and sorry for delay in replying it.

Just a small comment about using an existing type instead of creating a new one. If it work, please import it under TYPE_CHECKING section.

@leandrodamascena leandrodamascena self-requested a review November 24, 2024 14:10
@leandrodamascena leandrodamascena changed the title chore(router): add type annotations for Api Gateway Router decorators to improve Pyright compatibility refactor(event_handler): add type annotations for router decorators Nov 24, 2024
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 a lot for addressing the feedback @rafrafek!

APPROVED!

@leandrodamascena leandrodamascena merged commit 3726a4b into aws-powertools:develop Nov 24, 2024
14 checks passed
@github-actions github-actions bot added enhancement and removed bug Something isn't working internal Maintenance changes labels Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement event_handlers size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static typing: APIGatewayRestResolver .post() decorator return type Unknown
2 participants