Skip to content

Installing asgi_app middleware as documented results in type errors #438

@bcmills

Description

@bcmills

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions