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

Type mismatch a2wsgi.asgi_typing.*Scope and starlette.types.Scope #44

Closed
mvdbeek opened this issue Jan 1, 2024 · 1 comment
Closed

Comments

@mvdbeek
Copy link

mvdbeek commented Jan 1, 2024

Hey there, we're using a2wsgi and it helped us a lot, but with starlette 0.34.0 we've started seeing

lib/galaxy/webapps/galaxy/fast_app.py:184: error: Argument 2 to "mount" of "Starlette" has
incompatible type "WSGIMiddleware"; expected
"Callable[[MutableMapping[str, Any], Callable[[], Awaitable[MutableMapping[str, Any]]], Callable[[MutableMapping[str, Any]], Awaitable[None]]], Awaitable[None]]"
 [arg-type]
        app.mount("/", wsgi_handler)
                       ^~~~~~~~~~~~
lib/galaxy/webapps/galaxy/fast_app.py:184: note: "WSGIMiddleware.__call__" has type "Callable[[Arg(HTTPScope | WebSocketScope | LifespanScope, 'scope'), Arg(Callable[[], Awaitable[HTTPRequestEvent | HTTPDisconnectEvent | WebSocketConnectEvent | WebSocketReceiveEvent | WebSocketDisconnectEvent | LifespanStartupEvent | LifespanShutdownEvent]], 'receive'), Arg(Callable[[HTTPResponseStartEvent | HTTPResponseBodyEvent | HTTPDisconnectEvent | WebSocketAcceptEvent | WebSocketSendEvent | WebSocketCloseEvent | LifespanStartupCompleteEvent | LifespanStartupFailedEvent | LifespanShutdownCompleteEvent | LifespanShutdownFailedEvent], Awaitable[None]], 'send')], Coroutine[Any, Any, None]]"

I believe this is because a2wsgi uses TypedDict while starlette uses MutableMapping, which are not compatible. I'm not sure what the solution would be, maybe this is something I should raise at starlette, but it seems like one could in principle add arbitrary keys which would make TypedDict the wrong choice ?

mvdbeek added a commit to galaxybot/galaxy that referenced this issue Jan 1, 2024
Starlette removed some Any annotations in 0.34.0.
Issue tracked in abersheeran/a2wsgi#44
@abersheeran
Copy link
Owner

It's neither Starlette nor a2wsgi's problem, it's because Python currently doesn't handle extra keyword arguments gracefully. You can use type: ignore to work around it. The reason a2wsgi has detailed type annotations is that a2wsgi is supposed to work between frameworks that conform to those specifications. Detailed type annotations help to check for compatibility issues. As for web frameworks, they may prefer the looser MutableMapping since users tend to pass many non-spec keys and values.

@abersheeran abersheeran pinned this issue Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants