Closed eltoder closed 3 days ago
We can also consider making
_MiddlewareFactory
and moving it intostarlette.types
. This will make it easier to type arguments foradd_middleware()
This part I did not understand
@adriangb thank you for merging!
This part I did not understand
Sorry, missed a word:
We can also consider making _MiddlewareFactory
public.
The rationale is that add_middleware()
is a public function and occasionally I need to refer to the type of its argument. For example, I have a function that returns which middleware to use based on environment. I need to write its return type. With this PR I can write it as Callalble[]
, which is nice. But it may be even more clear and explicit to write it as MiddlewareFactory
. However, currently the latter is not public. Here's a sketch of how this can be used: https://mypy-play.net/?mypy=1.13.0&python=3.13&gist=e0652be937c8cfc1d56a5d4dafa0bd89
Summary
Make
app
a positional-only argument so that aCallable[[ASGIApp, ...], ASGIApp]
can be passed in place of_MiddlewareFactory
.We can also consider making
_MiddlewareFactory
and moving it intostarlette.types
. This will make it easier to type arguments foradd_middleware()
.Checklist