Skip to content

Commit

Permalink
Make _MiddlewareFactory compatible with Callable (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
eltoder authored Nov 26, 2024
1 parent 009a3ba commit 13d0c1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion starlette/middleware/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class _MiddlewareFactory(Protocol[P]):
def __call__(self, app: ASGIApp, *args: P.args, **kwargs: P.kwargs) -> ASGIApp: ... # pragma: no cover
def __call__(self, app: ASGIApp, /, *args: P.args, **kwargs: P.kwargs) -> ASGIApp: ... # pragma: no cover


class Middleware:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from contextlib import asynccontextmanager
from pathlib import Path
from typing import AsyncGenerator, AsyncIterator, Generator
from typing import AsyncGenerator, AsyncIterator, Callable, Generator

import anyio.from_thread
import pytest
Expand Down Expand Up @@ -567,9 +567,12 @@ async def _app(scope: Scope, receive: Receive, send: Send) -> None:

return _app

def get_middleware_factory() -> Callable[[ASGIApp, str], ASGIApp]:
return _middleware_factory

app = Starlette()
app.add_middleware(_middleware_factory, arg="foo")
app.add_middleware(_middleware_factory, arg="bar")
app.add_middleware(get_middleware_factory(), "bar")

with test_client_factory(app):
pass
Expand Down

0 comments on commit 13d0c1f

Please sign in to comment.