django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

Incompatibility between WSGIHandler and stdlib types in wsgiref

Open edwardpeek-crown-public opened this issue 3 years ago • 0 comments

Bug report

What's wrong

Changes to typing of core.handlers.WSGIHandler introduced in #909 are incompatible with the stdlib annotations under wsgiref, raising a error when checked with mypy:

from wsgiref.simple_server import make_server

from django.core.handlers.wsgi import WSGIHandler

make_server(
    "0.0.0.0",
    8080,
    WSGIHandler(),
)
example.py:8: error: Argument 3 to "make_server" has incompatible type "WSGIHandler"; expected "Callable[[Dict[str, Any], StartResponse], Iterable[bytes]]"  [arg-type]
scce.py:8: note: "WSGIHandler.__call__" has type "Callable[[Arg(Dict[str, Any], 'environ'), Arg(Callable[[str, Sequence[Tuple[str, str]], Optional[Any]], None], 'start_response')], HttpResponseBase]"
Found 1 error in 1 file (checked 1 source file)

wsgiref types are in typeshed Python <= 3.10, and in wsgiref.types as of Python 3.11.

How is that should be

Types should be compatible with stdlib as per PEP 3333.

System information

  • OS:
  • python version: 3.10
  • django version: 4.0.5
  • mypy version: 0.961
  • django-stubs version: 1.12.0
  • django-stubs-ext version: 0.5.0

edwardpeek-crown-public avatar Jul 07 '22 03:07 edwardpeek-crown-public