diff --git a/stdlib/2and3/_typeshed/wsgi.pyi b/stdlib/2and3/_typeshed/wsgi.pyi new file mode 100644 index 000000000..f79d54d3b --- /dev/null +++ b/stdlib/2and3/_typeshed/wsgi.pyi @@ -0,0 +1,32 @@ +# Types to support PEP 3333 (WSGI) +# +# This module doesn't exist at runtime and neither do the types defined in this +# file. They are provided for type checking purposes. + +from sys import _OptExcInfo +from typing import Callable, Dict, Iterable, List, Any, Text, Protocol, Tuple, Optional + +class StartResponse(Protocol): + def __call__(self, status: str, headers: List[Tuple[str, str]], exc_info: Optional[_OptExcInfo] = ...) -> Callable[[bytes], Any]: ... + +WSGIEnvironment = Dict[Text, Any] +WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] + +# WSGI input streams per PEP 3333 +class InputStream(Protocol): + def read(self, size: int = ...) -> bytes: ... + def readline(self, size: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def __iter__(self) -> Iterable[bytes]: ... + +# WSGI error streams per PEP 3333 +class ErrorStream(Protocol): + def flush(self) -> None: ... + def write(self, s: str) -> None: ... + def writelines(self, seq: List[str]) -> None: ... + +class _Readable(Protocol): + def read(self, size: int = ...) -> bytes: ... +# Optional file wrapper in wsgi.file_wrapper +class FileWrapper(Protocol): + def __call__(self, file: _Readable, block_size: int = ...) -> Iterable[bytes]: ... diff --git a/stdlib/2and3/wsgiref/types.pyi b/stdlib/2and3/wsgiref/types.pyi index 39a913eea..c272ae67c 100644 --- a/stdlib/2and3/wsgiref/types.pyi +++ b/stdlib/2and3/wsgiref/types.pyi @@ -1,44 +1,3 @@ -# Type declaration for a WSGI Function -# -# wsgiref/types.py doesn't exist and neither do the types defined in this -# file. They are provided for type checking purposes. -# -# This means you cannot simply import wsgiref.types in your code. Instead, -# use the `TYPE_CHECKING` flag from the typing module: -# -# from typing import TYPE_CHECKING -# -# if TYPE_CHECKING: -# from wsgiref.types import WSGIApplication -# -# This import is now only taken into account by the type checker. Consequently, -# you need to use 'WSGIApplication' and not simply WSGIApplication when type -# hinting your code. Otherwise Python will raise NameErrors. +# Obsolete, use _typeshed.wsgi directly. -from sys import _OptExcInfo -from typing import Callable, Dict, Iterable, List, Any, Text, Protocol, Tuple, Optional - -class StartResponse(Protocol): - def __call__(self, status: str, headers: List[Tuple[str, str]], exc_info: Optional[_OptExcInfo] = ...) -> Callable[[bytes], Any]: ... - -WSGIEnvironment = Dict[Text, Any] -WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] - -# WSGI input streams per PEP 3333 -class InputStream(Protocol): - def read(self, size: int = ...) -> bytes: ... - def readline(self, size: int = ...) -> bytes: ... - def readlines(self, hint: int = ...) -> List[bytes]: ... - def __iter__(self) -> Iterable[bytes]: ... - -# WSGI error streams per PEP 3333 -class ErrorStream(Protocol): - def flush(self) -> None: ... - def write(self, s: str) -> None: ... - def writelines(self, seq: List[str]) -> None: ... - -class _Readable(Protocol): - def read(self, size: int = ...) -> bytes: ... -# Optional file wrapper in wsgi.file_wrapper -class FileWrapper(Protocol): - def __call__(self, file: _Readable, block_size: int = ...) -> Iterable[bytes]: ... +from _typeshed.wsgi import * diff --git a/stdlib/2and3/wsgiref/validate.pyi b/stdlib/2and3/wsgiref/validate.pyi index c7fa699fc..b03e7889f 100644 --- a/stdlib/2and3/wsgiref/validate.pyi +++ b/stdlib/2and3/wsgiref/validate.pyi @@ -1,7 +1,7 @@ import sys from typing import Any, Iterable, Iterator, Optional, NoReturn, Callable -from wsgiref.types import WSGIApplication, InputStream, ErrorStream +from _typeshed.wsgi import WSGIApplication, InputStream, ErrorStream class WSGIWarning(Warning): ... diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 8b6461e02..bb8609bd4 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -5,7 +5,7 @@ _importlib_modulespec _operator.methodcaller _threading_local.local.__new__ _types -_typeshed +_typeshed.* # Utility types for typeshed, doesn't exist at runtime _weakref.CallableProxyType.__getattr__ _weakref.ProxyType.__getattr__ _weakref.ReferenceType.__call__ diff --git a/third_party/2and3/werkzeug/contrib/fixers.pyi b/third_party/2and3/werkzeug/contrib/fixers.pyi index 0593d9d87..aacf84aab 100644 --- a/third_party/2and3/werkzeug/contrib/fixers.pyi +++ b/third_party/2and3/werkzeug/contrib/fixers.pyi @@ -1,5 +1,5 @@ from typing import Any, Iterable, List, Mapping, Optional, Sequence, Set, Text -from wsgiref.types import WSGIApplication, WSGIEnvironment, StartResponse +from _typeshed.wsgi import WSGIApplication, WSGIEnvironment, StartResponse from ..middleware.proxy_fix import ProxyFix as ProxyFix diff --git a/third_party/2and3/werkzeug/exceptions.pyi b/third_party/2and3/werkzeug/exceptions.pyi index 41f8012b5..64597646c 100644 --- a/third_party/2and3/werkzeug/exceptions.pyi +++ b/third_party/2and3/werkzeug/exceptions.pyi @@ -1,7 +1,7 @@ import datetime from typing import Any, Dict, Tuple, List, Text, NoReturn, Optional, Protocol, Type, Union, Iterable -from wsgiref.types import WSGIEnvironment, StartResponse +from _typeshed.wsgi import WSGIEnvironment, StartResponse from werkzeug.wrappers import Response class _EnvironContainer(Protocol): diff --git a/third_party/2and3/werkzeug/formparser.pyi b/third_party/2and3/werkzeug/formparser.pyi index 8f0b55254..287c4a080 100644 --- a/third_party/2and3/werkzeug/formparser.pyi +++ b/third_party/2and3/werkzeug/formparser.pyi @@ -1,5 +1,5 @@ from typing import Any, Optional, Text, Tuple, Callable, Iterable, TypeVar, NoReturn, Protocol, IO, Generator, Dict, Mapping, Union -from wsgiref.types import WSGIEnvironment +from _typeshed.wsgi import WSGIEnvironment from .datastructures import Headers diff --git a/third_party/2and3/werkzeug/http.pyi b/third_party/2and3/werkzeug/http.pyi index bdda6d2cd..ff1760a6e 100644 --- a/third_party/2and3/werkzeug/http.pyi +++ b/third_party/2and3/werkzeug/http.pyi @@ -4,7 +4,7 @@ from typing import ( Dict, Text, Union, Tuple, Any, Optional, Mapping, Iterable, Callable, List, Type, TypeVar, Protocol, overload, SupportsInt, ) -from wsgiref.types import WSGIEnvironment +from _typeshed.wsgi import WSGIEnvironment from .datastructures import ( Headers, Accept, RequestCacheControl, HeaderSet, Authorization, WWWAuthenticate, diff --git a/third_party/2and3/werkzeug/middleware/dispatcher.pyi b/third_party/2and3/werkzeug/middleware/dispatcher.pyi index f107c4356..400b611c8 100644 --- a/third_party/2and3/werkzeug/middleware/dispatcher.pyi +++ b/third_party/2and3/werkzeug/middleware/dispatcher.pyi @@ -1,5 +1,5 @@ from typing import Any, Iterable, Mapping, Optional, Text -from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment +from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment class DispatcherMiddleware(object): app: WSGIApplication diff --git a/third_party/2and3/werkzeug/middleware/http_proxy.pyi b/third_party/2and3/werkzeug/middleware/http_proxy.pyi index 4056cacc2..2666d52b8 100644 --- a/third_party/2and3/werkzeug/middleware/http_proxy.pyi +++ b/third_party/2and3/werkzeug/middleware/http_proxy.pyi @@ -1,5 +1,5 @@ from typing import Any, Dict, Iterable, Mapping, MutableMapping, Text -from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment +from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment _Opts = Mapping[Text, Any] _MutableOpts = MutableMapping[Text, Any] diff --git a/third_party/2and3/werkzeug/middleware/lint.pyi b/third_party/2and3/werkzeug/middleware/lint.pyi index 95922cc4a..7531d7752 100644 --- a/third_party/2and3/werkzeug/middleware/lint.pyi +++ b/third_party/2and3/werkzeug/middleware/lint.pyi @@ -1,6 +1,6 @@ import sys from typing import Any, Iterable, Iterator, List, Mapping, Optional, Protocol, Tuple -from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment +from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment from ..datastructures import Headers diff --git a/third_party/2and3/werkzeug/middleware/profiler.pyi b/third_party/2and3/werkzeug/middleware/profiler.pyi index 75051220f..2f7e80719 100644 --- a/third_party/2and3/werkzeug/middleware/profiler.pyi +++ b/third_party/2and3/werkzeug/middleware/profiler.pyi @@ -1,5 +1,5 @@ from typing import IO, Iterable, List, Optional, Text, Tuple, Union -from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment +from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment class ProfilerMiddleware(object): def __init__( diff --git a/third_party/2and3/werkzeug/middleware/proxy_fix.pyi b/third_party/2and3/werkzeug/middleware/proxy_fix.pyi index 764fc6f07..3b6a9c10e 100644 --- a/third_party/2and3/werkzeug/middleware/proxy_fix.pyi +++ b/third_party/2and3/werkzeug/middleware/proxy_fix.pyi @@ -1,5 +1,5 @@ from typing import Iterable, Optional -from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment +from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment class ProxyFix(object): app: WSGIApplication diff --git a/third_party/2and3/werkzeug/middleware/shared_data.pyi b/third_party/2and3/werkzeug/middleware/shared_data.pyi index d1284e831..7ccd12d66 100644 --- a/third_party/2and3/werkzeug/middleware/shared_data.pyi +++ b/third_party/2and3/werkzeug/middleware/shared_data.pyi @@ -1,6 +1,6 @@ import datetime from typing import Callable, IO, Iterable, List, Mapping, Optional, Text, Tuple, Union -from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment +from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment _V = Union[Tuple[Text, Text], Text] diff --git a/third_party/2and3/werkzeug/test.pyi b/third_party/2and3/werkzeug/test.pyi index 764b76d8e..2d882ce66 100644 --- a/third_party/2and3/werkzeug/test.pyi +++ b/third_party/2and3/werkzeug/test.pyi @@ -1,5 +1,5 @@ import sys -from wsgiref.types import WSGIEnvironment +from _typeshed.wsgi import WSGIEnvironment from typing import Any, Generic, Optional, Text, Tuple, Type, TypeVar, overload from typing_extensions import Literal diff --git a/third_party/2and3/werkzeug/wrappers.pyi b/third_party/2and3/werkzeug/wrappers.pyi index 2b8b34ffe..ea1b01119 100644 --- a/third_party/2and3/werkzeug/wrappers.pyi +++ b/third_party/2and3/werkzeug/wrappers.pyi @@ -3,7 +3,7 @@ from datetime import datetime from typing import ( Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Text, Tuple, Type, TypeVar, Union, overload ) -from wsgiref.types import WSGIEnvironment, InputStream +from _typeshed.wsgi import WSGIEnvironment, InputStream from .datastructures import ( Authorization, CombinedMultiDict, EnvironHeaders, Headers, ImmutableMultiDict, diff --git a/third_party/2and3/werkzeug/wsgi.pyi b/third_party/2and3/werkzeug/wsgi.pyi index c7863cdd6..dbc0c666c 100644 --- a/third_party/2and3/werkzeug/wsgi.pyi +++ b/third_party/2and3/werkzeug/wsgi.pyi @@ -1,5 +1,5 @@ from typing import Any, Optional, Protocol, Iterable, Text -from wsgiref.types import WSGIEnvironment, InputStream +from _typeshed.wsgi import WSGIEnvironment, InputStream from .middleware.dispatcher import DispatcherMiddleware as DispatcherMiddleware from .middleware.http_proxy import ProxyMiddleware as ProxyMiddleware