abersheeran / a2wsgi

Convert WSGI app to ASGI app or ASGI app to WSGI app.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type Issue when Passing Flask App to WSGIMiddleware

cancan101 opened this issue · comments

I am attempting to pass a flask app to WSGIMiddleware:

from a2wsgi import WSGIMiddleware
from flask import Flask

app = Flask(__name__)
mw = WSGIMiddleware(app=app)

but am getting the following error from mypy:

my_app/__init__.py:14: error: Argument "app" to "WSGIMiddleware" has incompatible type "Flask"; expected "Callable[[MutableMapping[str, Any], Callable[[str, Iterable[Tuple[str, str]], Optional[Tuple[Type[BaseException], BaseException, Optional[TracebackType]]]], None]], Iterable[bytes]]"  [arg-type]
my_app/__init__.py:14: note: "Flask.__call__" has type "Callable[[Arg(Dict[Any, Any], 'environ'), Arg(Callable[..., Any], 'start_response')], Any]"

Using:

flask==2.2.3
a2wsgi==1.7.0
commented

WSGI does not have a unified Type hint Interface so far. You can temporarily use type: ignore to solve the problem.

Some related issues: python/typing#795