Some small tweaks to Werkzeug stubs: (#2784)

* default_exceptions is a dict of classes, not instances
* Correctly overload 'redirect' to get the proper return type
* Request.get_data() is an Any (not bytes), just like Response.get_data
This commit is contained in:
lincolnq
2019-02-09 19:30:28 +00:00
committed by Sebastian Rittau
parent c8c6271365
commit b00bb54dc5
3 changed files with 14 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ class HTTPException(Exception):
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]
default_exceptions: Dict[int, Type[HTTPException]]
class BadRequest(HTTPException):
code = ... # type: int

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any, Optional, overload, Type, TypeVar
from werkzeug._internal import _DictAccessorProperty
from werkzeug.wrappers import Response
@@ -31,7 +31,15 @@ def format_string(string, context): ...
def secure_filename(filename): ...
def escape(s, quote: Optional[Any] = ...): ...
def unescape(s): ...
def redirect(location, code: int = ..., Response: Optional[Any] = ...) -> Response: ...
# 'redirect' returns a werkzeug Response, unless you give it
# another Response type to use instead.
_RC = TypeVar("_RC", bound=Response)
@overload
def redirect(location, code: int = ..., Response: None = ...) -> Response: ...
@overload
def redirect(location, code: int = ..., Response: Type[_RC] = ...) -> _RC: ...
def append_slash_redirect(environ, code: int = ...): ...
def import_string(import_name, silent: bool = ...): ...
def find_modules(import_path, include_packages: bool = ..., recursive: bool = ...): ...

View File

@@ -43,7 +43,8 @@ class BaseRequest:
args = ... # type: ImmutableMultiDict
@property
def data(self) -> bytes: ...
def get_data(self, cache: bool = ..., as_text: bool = ..., parse_form_data: bool = ...) -> bytes: ...
# TODO: once Literal types are supported, overload with as_text
def get_data(self, cache: bool = ..., as_text: bool = ..., parse_form_data: bool = ...) -> Any: ... # returns bytes if as_text is False (the default), else Text
form = ... # type: ImmutableMultiDict
values = ... # type: CombinedMultiDict
files = ... # type: MultiDict
@@ -105,6 +106,7 @@ class BaseResponse:
def force_type(cls: Type[_SelfT], response: object, environ: Optional[WSGIEnvironment] = ...) -> _SelfT: ...
@classmethod
def from_app(cls: Type[_SelfT], app: Any, environ: WSGIEnvironment, buffered: bool = ...) -> _SelfT: ...
# TODO: once Literal types are supported, overload with as_text
def get_data(self, as_text: bool = ...) -> Any: ... # returns bytes if as_text is False (the default), else Text
def set_data(self, value: Union[bytes, Text]) -> None: ...
data = ... # type: Any