Enhance ASGI scope typing and add HTTP event types#2638
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2638 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 7976 8009 +33
Branches 1102 1102
=========================================
+ Hits 7976 8009 +33 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
vytas7
left a comment
There was a problem hiding this comment.
Hi @MustafaNazir11, and thanks for this PR.
The main goal of these improved annotations was to get rid of typing ignores, however, you haven't removed any.
See also inline comments.
You've checked that you ran tox yourself, but that is obviously not true (see the failing CI).
Taking all these points into account, I believe it would be more efficient to restart this PR from scratch.
|
|
||
| req = self._request_type( | ||
| scope, receive, first_event=first_event, options=self.req_options | ||
| cast(dict[str, Any], scope), receive, first_event=first_event, options=self.req_options |
There was a problem hiding this comment.
This is the hottest code path in Falcon, we simply cannot afford cast(...) here.
| WS_DISCONNECT = 'websocket.disconnect' | ||
| WS_CLOSE = 'websocket.close' | ||
|
|
||
| class HTTPRequestEvent(TypedDict, total=False): |
There was a problem hiding this comment.
I see how these could belong to asgi_spec.py too, but let's colocate these aliases in falcon/_typing.py for now.
Summary of Changes
Introduce TypedDict definitions for ASGI HTTP event messages.
This improves type clarity and lays the groundwork for stricter typing in the future without affecting runtime behavior.
Related Issues
Relates to #2628
Pull Request Checklist
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. Reading our contribution guide at least once will save you a few review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.
tox.docs/.docs/.versionadded,versionchanged, ordeprecateddirectives.docs/_newsfragments/, with the file name format{issue_number}.{fragment_type}.rst. (Runtox -e towncrier, and inspectdocs/_build/html/changes/in the browser to ensure it renders correctly.)If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!
PR template inspired by the attrs project.