From 1f9895f95f2615df3134ca77fe45b0407107d381 Mon Sep 17 00:00:00 2001 From: Michael Oliver Date: Tue, 29 Nov 2022 19:59:26 +0000 Subject: [PATCH 1/3] Use wsgi types from typeshed --- httpx/_transports/wsgi.py | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/httpx/_transports/wsgi.py b/httpx/_transports/wsgi.py index f27a77aea6..290bb21508 100644 --- a/httpx/_transports/wsgi.py +++ b/httpx/_transports/wsgi.py @@ -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]] +if typing.TYPE_CHECKING: + from _typeshed import OptExcInfo + from _typeshed.wsgi import WSGIApplication - -# 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], -] - - -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 @@ def handle_request(self, request: Request) -> Response: 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 From 1fd01ddeb0bc9737c57a1c30caf144304e34a687 Mon Sep 17 00:00:00 2001 From: Michael Oliver Date: Wed, 30 Nov 2022 09:23:04 +0000 Subject: [PATCH 2/3] Fix --- httpx/_transports/wsgi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpx/_transports/wsgi.py b/httpx/_transports/wsgi.py index 290bb21508..a7eb4bba10 100644 --- a/httpx/_transports/wsgi.py +++ b/httpx/_transports/wsgi.py @@ -11,7 +11,7 @@ from _typeshed import OptExcInfo from _typeshed.wsgi import WSGIApplication - _T = typing.TypeVar("_T") +_T = typing.TypeVar("_T") def _skip_leading_empty_chunks(body: typing.Iterable[_T]) -> typing.Iterable[_T]: From f444a25b12e30382c90a27199b3383ba8d31c96c Mon Sep 17 00:00:00 2001 From: Michael Oliver Date: Wed, 30 Nov 2022 09:27:08 +0000 Subject: [PATCH 3/3] Use `# pragma: no cover` comment on typeshed imports --- httpx/_transports/wsgi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpx/_transports/wsgi.py b/httpx/_transports/wsgi.py index a7eb4bba10..33035ce586 100644 --- a/httpx/_transports/wsgi.py +++ b/httpx/_transports/wsgi.py @@ -8,8 +8,8 @@ from .base import BaseTransport if typing.TYPE_CHECKING: - from _typeshed import OptExcInfo - from _typeshed.wsgi import WSGIApplication + from _typeshed import OptExcInfo # pragma: no cover + from _typeshed.wsgi import WSGIApplication # pragma: no cover _T = typing.TypeVar("_T")