mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 04:34:28 +08:00
Move wsgiref.types to _typeshed.wsgi (#4175)
Re-export the types from wsgiref.types for now to avoid breaking existing code. wsgiref.types should be removed eventually. Also, reduce the boilerplate description in _typeshed/wsgi.pyi as it mirrors the description in _typeshed/__init__.pyi.
This commit is contained in:
32
stdlib/2and3/_typeshed/wsgi.pyi
Normal file
32
stdlib/2and3/_typeshed/wsgi.pyi
Normal file
@@ -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]: ...
|
||||
@@ -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 *
|
||||
|
||||
@@ -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): ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user