refactor(typing): Update event_handler to pass strict checks
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.
- [x] Meet tenets criteria
- [x] I have performed a self-review of this change
- [ ] Changes have been tested
- [ ] Changes are documented
- [x] PR title follows conventional commit semantics
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.
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?
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
45.0% Duplication on New Code
Hi @BVMiko! I'll close this PR and create a new one targeting the develop branch. I'll give you credit in the release notes.
Actually it was resolved here: https://github.com/aws-powertools/powertools-lambda-python/pull/5601