-
-
Notifications
You must be signed in to change notification settings - Fork 917
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
HTTPConnection::__get_item__ has incorrect type signature #1117
Labels
typing
Type annotations or mypy issues
Comments
sburba
added a commit
to sburba/starlette
that referenced
this issue
Dec 28, 2020
Scope does not only contain strings, see full spec here: https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope Fixes encode#1117
Kludex
added a commit
that referenced
this issue
Sep 18, 2021
Scope does not only contain strings, see full spec here: https://asgi.readthedocs.io/en/latest/specs/www.html#websocket-connection-scope Fixes #1117 Co-authored-by: Marcelo Trylesinski <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checklist
master
.Describe the bug
HTTPConnection
's__get_item__
has the return typestr
. However, it returns the value for the provided key in the scope. Not all values in the scope are strings, (See documentation here: https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scopeSince
WebSocket
inherits this method it also has the wrong return type.To reproduce
This example uses WebSocket because that's how I originally found the issue.
Run mypy
On the following code
Expected behavior
mypy typecheck should pass for valid code
Actual behavior
Mypy fails to typecheck with the following error:
Environment
Additional context
Changing the return type of
__get_item__
toAny
is likely the right thing to do here, which would be backwards-compatible for those currently using mypy.As an extra solution to this problem, it would be great to expose the correct types for the scope using a TypedDict (couldn't be done for
__getitem__
, but could be done for the scope attribute onWebSocket
andHTTPConnection
), although that would be a breaking change for MyPy users, and also complicate the middleware story.I'd be happy to work on either/both of these solutions if there's a consensus on what the right direction is.
The text was updated successfully, but these errors were encountered: