pallets / pallets/quart

Installing asgi_app middleware as documented results in type errors

Open
#438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3.7k
Forks
206
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the middleware guide and Quart.asgi_app reference linked in the issue, then reproduce the example with Python 3.12.8, Quart 0.20.0, OpenTelemetryMiddleware, and mypy 1.15.0. Trace the declared type of app.asgi_app and the middleware callable. Done means the documented installation path is accurate and the reported mypy errors are addressed or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.