quart icon indicating copy to clipboard operation
quart copied to clipboard

Installing asgi_app middleware as documented results in type errors

Open bcmills opened this issue 5 months ago • 0 comments

The documentation in https://quart.palletsprojects.com/en/latest/how_to_guides/middleware/ and https://quart.palletsprojects.com/en/latest/reference/source/quart.app/#quart.app.Quart.asgi_app says to install middleware using a pattern like:

app.asgi_app = middleware(app.asgi_app)

However, following that pattern in practice produces type errors with mypy 1.15.0.


After adding

from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware

and

    app.asgi_app = OpenTelemetryMiddleware(app.asgi_app)

I see:

app.py:388: error: Cannot assign to a method  [method-assign]
app.py:388: error: Incompatible types in assignment (expression has type "OpenTelemetryMiddleware", variable has type "Callable[[HTTPScope | WebsocketScope | LifespanScope, Callable[[], Awaitable[HTTPRequestEvent | HTTPDisconnectEvent | WebsocketConnectEvent | WebsocketReceiveEvent | WebsocketDisconnectEvent | LifespanStartupEvent | LifespanShutdownEvent]], Callable[[HTTPResponseStartEvent | HTTPResponseBodyEvent | HTTPResponseTrailersEvent | HTTPServerPushEvent | HTTPEarlyHintEvent | <10 more items>], Awaitable[None]]], Coroutine[Any, Any, None]]")  [assignment]
app.py:388: note: "OpenTelemetryMiddleware.__call__" has type "Callable[[Arg(dict[str, Any], 'scope'), Arg(Callable[[], Awaitable[dict[str, Any]]], 'receive'), Arg(Callable[[dict[str, Any]], Awaitable[None]], 'send')], Coroutine[Any, Any, None]]"

Environment:

  • Python version: 3.12.8
  • Quart version: 0.20.0

bcmills avatar Jul 02 '25 18:07 bcmills