Skip to content

Commit

Permalink
fix(types): use MutableMapping to type call arguments in asgi middleware
Browse files Browse the repository at this point in the history
When we bumped `opentelemetry-instrumentation-asgi` to 0.45b0, we got type errors due to the changes introduced by PR open-telemetry#2026.

```
error: Argument 1 to "add_middleware" of "Starlette" has incompatible type "type[AsgiMiddleware]"; expected "type[_MiddlewareClass[[]]]"  [arg-type]
```

The problem is that it is specifying the types as `dict`, whereas Starlette requires `MutableMapping`. See https://github.com/encode/starlette/blob/9f16bf5c25e126200701f6e04330864f4a91a898/starlette/types.py#L10-L14.

I first tried to change the type to `MutableMapping`, but that produces lot of extra changes as the code is not fully typed and we seem to be using `dict`s everywhere.
  • Loading branch information
sk- committed May 29, 2024
1 parent bd9156f commit 2e91519
Showing 1 changed file with 1 addition and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,7 @@ def __init__(
or []
)

async def __call__(
self,
scope: dict[str, Any],
receive: Callable[[], Awaitable[dict[str, Any]]],
send: Callable[[dict[str, Any]], Awaitable[None]],
) -> None:
async def __call__(self, scope, receive, send) -> None:
"""The ASGI application
Args:
Expand Down

0 comments on commit 2e91519

Please sign in to comment.