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(typing): Update event_handler to pass strict checks #5139

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

BVMiko
Copy link
Contributor

@BVMiko BVMiko commented Sep 7, 2024

While testing out moving an APIGatewayRestResolver projects to run mypy in strict mode, I noticed that 4 areas were failing type inference:

router = Router()

throws: error: Call to untyped function "Router" in typed context [no-untyped-call]

and

@router.get('/hello')
def hello_get() -> Response[str]:
    return Response(200, body="Hello World!")

throws: error: Untyped decorator makes function "hello_get" untyped [misc]

and

@app.exception_handler(Exception)
def handle_generic_exception(exception: Exception) -> Response[str]:
    return Response(500, 'error')

throws: error: Untyped decorator makes function "handle_generic_exception" untyped [misc]

and

foo = 42
app.append_context(foo=foo)

throws: error: Call to untyped function "append_context" in typed context [no-untyped-call]

Issue number:

Summary

Changes

Added some simple type definitions to affected areas of these 4 components.

User experience

The above code examples will not raise errors when running mypy --strict

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.

@BVMiko BVMiko requested a review from a team as a code owner September 7, 2024 19:19
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 7, 2024
Copy link

sonarcloud bot commented Sep 7, 2024

@leandrodamascena
Copy link
Contributor

Hi @BVMiko! Thanks for submitting this PR! Can I ask you to open an issue telling us what problem you want to solve here? We love explaining the challenges customers face and how they can contribute to solving them.

Also, I see mypy complaining about types, can you please check?

@dreamorosi dreamorosi added on-hold This item is on-hold and will be revisited in the future labels Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement event_handlers on-hold This item is on-hold and will be revisited in the future 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.

3 participants