-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
What is the "right way" to annotate a wsgi application with middlewares? #7585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It should be safe to use the |
Ah, I hadn't found that readme -- and particularly the API stability note. Thank you! That solves my scenario nicely. It would still be nice to get these types into |
I'd like to hear if @srittau has more input here. We've talked in the past about making |
Please see bpo-42012. Maybe a core developer (wink wink) could comment on this. |
I just looked to see if I could maybe help with this work, and I see python/cpython#32335 already open! As the OP, I think it's reasonable to close this and am doing so now. It will take a while for most people to be able to use the types in the stdlib, but things are on a good course. Every time I try to help with typeshed and typing it's a pleasure. Thanks so much to everyone involved! π |
I'm working with
flask
andwerkzeug
, and trying to figure out how to improve some of my typing (mypy --disallow-untyped-defs
). When I look at the types from typeshed for wsgiref, and how werkzeug handles this, I find things that are a bit confusing. This question is only somewhat flask/werkzeug specific, it mostly pertains to typeshed -- I'm happy to repost or cross-post in werkzeug if that seems better.Here's something similar to what I have today, partially annotated:
So what is the return type of
apply_middlewares
?Looking around, it seems like this is
_typeshed.wsgi.WSGIApplication
. But that's in_typeshed
-- is it safe to import it at type-checking time? Could it be renamed in the future?werkzeug
already does this:Is this safe for me to do too? I'm going to probably do this for today but it would be great to either know that the name is stable or to find a better way.
Concretely, the type above is just
Flask | ProfilerMiddleware
today. But any other middleware will (spuriously) be flagged as changing the type if the code changes. SoWSGIApplication
is really much preferable.I'd really like to see
WSGIApplication
(and some of the other stuff, likeStartResponse
) available as types that I can use at typing time. Does this require additions of some of these types as protocols to the stdlib? I'm more than happy to work on this, if it's not already in progress.The text was updated successfully, but these errors were encountered: