]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Use wsgi types from typeshed (#2478)
authorMichael Oliver <michael@michaeloliver.dev>
Wed, 30 Nov 2022 09:48:51 +0000 (09:48 +0000)
committerGitHub <noreply@github.com>
Wed, 30 Nov 2022 09:48:51 +0000 (09:48 +0000)
httpx/_transports/wsgi.py

index f27a77aea6c3f9aec8bac9344b32c4a413dc850b..33035ce586312d8722893e288a1bcadb20548a3f 100644 (file)
@@ -1,28 +1,17 @@
 import io
 import itertools
 import sys
-import types
 import typing
 
 from .._models import Request, Response
 from .._types import SyncByteStream
 from .base import BaseTransport
 
-_T = typing.TypeVar("_T")
-_ExcInfo = typing.Tuple[typing.Type[BaseException], BaseException, types.TracebackType]
-_OptExcInfo = typing.Union[_ExcInfo, typing.Tuple[None, None, None]]
-
-
-# backported wsgiref.types definitions from Python 3.11
-StartResponse = typing.Callable[
-    [str, typing.List[typing.Tuple[str, str]], typing.Optional[_OptExcInfo]],
-    typing.Callable[[bytes], object],
-]
+if typing.TYPE_CHECKING:
+    from _typeshed import OptExcInfo  # pragma: no cover
+    from _typeshed.wsgi import WSGIApplication  # pragma: no cover
 
-
-WSGIApplication = typing.Callable[
-    [typing.Dict[str, typing.Any], StartResponse], typing.Iterable[bytes]
-]
+_T = typing.TypeVar("_T")
 
 
 def _skip_leading_empty_chunks(body: typing.Iterable[_T]) -> typing.Iterable[_T]:
@@ -82,7 +71,7 @@ class WSGITransport(BaseTransport):
 
     def __init__(
         self,
-        app: WSGIApplication,
+        app: "WSGIApplication",
         raise_app_exceptions: bool = True,
         script_name: str = "",
         remote_addr: str = "127.0.0.1",
@@ -128,7 +117,7 @@ class WSGITransport(BaseTransport):
         def start_response(
             status: str,
             response_headers: typing.List[typing.Tuple[str, str]],
-            exc_info: typing.Optional[_OptExcInfo] = None,
+            exc_info: typing.Optional["OptExcInfo"] = None,
         ) -> typing.Callable[[bytes], typing.Any]:
             nonlocal seen_status, seen_response_headers, seen_exc_info
             seen_status = status