Skip to content

Conversation

@decorator-factory
Copy link

@decorator-factory decorator-factory commented May 1, 2021

  1. Right now, it's possible to pass a sequence of tuples (callable, options) where callable is a callable accepting **options and returning an ASGI app. But the type annotation on Starlette says that one has to pass a sequence of Middleware objects.
    This PR allows passing in a sequence of tuples as well as a list of Middleware objects

  2. Type annotations only allow classes to be used as middleware, but it's possible to provide any callable that returns an ASGI app. This PR fixes that as well.

@lovelydinosaur
Copy link
Contributor

Thanks. Honestly I'd rather prefer we don't add extra options here.
Keeping things constrained to one particular style helps keep everything just a little bit more simple.

@decorator-factory
Copy link
Author

That's understandable. But why can't I use a function as an ASGI app? It works just fine at runtime.

@graingert
Copy link
Contributor

I'm in favour of this being a Callable[[], asgiref.typing.ASGI3App]

@Kludex
Copy link
Owner

Kludex commented Dec 11, 2021

I'll go with Tom on the applications.py - too complex. But I think the cls parameter needs a change of type on the Middleware.__init__.

I'm in favour of this being a Callable[[], asgiref.typing.ASGI3App]

We don't have asgiref here yet.

I'll close this based on @tomchristie 's and my own comments, and the fact that the goal of the PR was to attack the middleware parameter (cls was just a side effect). Thanks for effort @decorator-factory .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants