From 50a62b6a6a9f472c502da51b62e322be228eb878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Tr=C4=99bski?= Date: Wed, 22 Aug 2018 17:49:11 +0200 Subject: [PATCH] Improve werkzeug/exceptions typings (#2405) --- third_party/2and3/werkzeug/exceptions.pyi | 153 +++++++++++----------- 1 file changed, 80 insertions(+), 73 deletions(-) diff --git a/third_party/2and3/werkzeug/exceptions.pyi b/third_party/2and3/werkzeug/exceptions.pyi index 44ffbc054..2529af9d2 100644 --- a/third_party/2and3/werkzeug/exceptions.pyi +++ b/third_party/2and3/werkzeug/exceptions.pyi @@ -1,152 +1,159 @@ -from typing import Any, Dict, NoReturn +from typing import Any, Dict, Tuple, List, Text, NoReturn, Optional, Protocol, Type, Union, Iterable + +from wsgiref.types import WSGIEnvironment, StartResponse +from werkzeug.wrappers import Response + +class _EnvironContainer(Protocol): + @property + def environ(self) -> WSGIEnvironment: ... class HTTPException(Exception): - code = ... # type: Any - description = ... # type: Any - response = ... # type: Any - def __init__(self, description=None, response=None): ... + code = ... # type: Optional[int] + description = ... # type: Optional[str] + response = ... # type: Optional[Response] + def __init__(self, description: Optional[str] = ..., response: Optional[Response] = ...) -> None: ... @classmethod - def wrap(cls, exception, name=None): ... + def wrap(cls, exception: Type[Exception], name: Optional[str] = ...) -> Any: ... @property - def name(self): ... - def get_description(self, environ=None): ... - def get_body(self, environ=None): ... - def get_headers(self, environ=None): ... - def get_response(self, environ=None): ... - def __call__(self, environ, start_response): ... + def name(self) -> str: ... + def get_description(self, environ: Optional[WSGIEnvironment] = ...) -> Text: ... + def get_body(self, environ: Optional[WSGIEnvironment] = ...) -> Text: ... + def get_headers(self, environ: Optional[WSGIEnvironment] = ...) -> List[Tuple[str, str]]: ... + def get_response(self, environ: Optional[Union[WSGIEnvironment, _EnvironContainer]] = ...) -> Response: ... + def __call__(self, environ: WSGIEnvironment, start_response: StartResponse) -> Iterable[bytes]: ... default_exceptions: Dict[int, HTTPException] class BadRequest(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class ClientDisconnected(BadRequest): ... class SecurityError(BadRequest): ... class BadHost(BadRequest): ... class Unauthorized(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class Forbidden(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class NotFound(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class MethodNotAllowed(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str valid_methods = ... # type: Any def __init__(self, valid_methods=None, description=None): ... def get_headers(self, environ): ... class NotAcceptable(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class RequestTimeout(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class Conflict(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class Gone(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class LengthRequired(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class PreconditionFailed(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class RequestEntityTooLarge(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class RequestURITooLarge(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class UnsupportedMediaType(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class RequestedRangeNotSatisfiable(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str length = ... # type: Any units = ... # type: Any def __init__(self, length=None, units='', description=None): ... def get_headers(self, environ): ... class ExpectationFailed(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class ImATeapot(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class UnprocessableEntity(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class Locked(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class PreconditionRequired(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class TooManyRequests(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class RequestHeaderFieldsTooLarge(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class UnavailableForLegalReasons(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class InternalServerError(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class NotImplemented(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class BadGateway(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class ServiceUnavailable(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class GatewayTimeout(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class HTTPVersionNotSupported(HTTPException): - code = ... # type: Any - description = ... # type: Any + code = ... # type: int + description = ... # type: str class Aborter: mapping = ... # type: Any - def __init__(self, mapping=None, extra=None): ... - def __call__(self, code, *args, **kwargs) -> NoReturn: ... + def __init__(self, mapping=None, extra=None) -> None: ... + def __call__(self, code: Union[int, Response], *args: Any, **kwargs: Any) -> NoReturn: ... -def abort(status: Any, *args: Any, **kwargs: Any) -> NoReturn: ... +def abort(status: Union[int, Response], *args: Any, **kwargs: Any) -> NoReturn: ...