Skip to content

Commit 0c15e5b

Browse files
JelleZijlstraambv
authored andcommitted
Improve werkzeug stubs (#1730)
1 parent 4563c5a commit 0c15e5b

File tree

2 files changed

+65
-61
lines changed

2 files changed

+65
-61
lines changed

third_party/2/werkzeug/wrappers.pyi

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
from typing import (
3-
Any, Iterable, Mapping, MutableMapping, Optional, Sequence, Tuple, Type,
4-
Union,
3+
Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Text,
4+
Tuple, Type, TypeVar, Union,
55
)
66

77
from wsgiref.types import WSGIEnvironment
@@ -14,13 +14,13 @@ from .datastructures import (
1414
class BaseRequest:
1515
charset = ... # type: str
1616
encoding_errors = ... # type: str
17-
max_content_length = ... # type: Union[int, long]
18-
max_form_memory_size = ... # type: Union[int, long]
17+
max_content_length = ... # type: int
18+
max_form_memory_size = ... # type: int
1919
parameter_storage_class = ... # type: Type
2020
list_storage_class = ... # type: Type
2121
dict_storage_class = ... # type: Type
2222
form_data_parser_class = ... # type: Type
23-
trusted_hosts = ... # type: Optional[Sequence[unicode]]
23+
trusted_hosts = ... # type: Optional[Sequence[Text]]
2424
disable_data_descriptor = ... # type: Any
2525
environ: WSGIEnvironment = ...
2626
shallow = ... # type: Any
@@ -41,34 +41,37 @@ class BaseRequest:
4141
input_stream = ... # type: Any
4242
args = ... # type: ImmutableMultiDict
4343
@property
44-
def data(self) -> str: ...
45-
def get_data(self, cache: bool = ..., as_text: bool = ..., parse_form_data: bool = ...) -> str: ...
44+
def data(self) -> bytes: ...
45+
def get_data(self, cache: bool = ..., as_text: bool = ..., parse_form_data: bool = ...) -> bytes: ...
4646
form = ... # type: ImmutableMultiDict
4747
values = ... # type: CombinedMultiDict
4848
files = ... # type: MultiDict
4949
cookies = ... # type: TypeConversionDict
5050
headers = ... # type: EnvironHeaders
51-
path = ... # type: unicode
52-
full_path = ... # type: unicode
53-
script_root = ... # type: unicode
54-
url = ... # type: unicode
55-
base_url = ... # type: unicode
56-
url_root = ... # type: unicode
57-
host_url = ... # type: unicode
58-
host = ... # type: unicode
59-
query_string = ... # type: str
60-
method = ... # type: str
51+
path = ... # type: Text
52+
full_path = ... # type: Text
53+
script_root = ... # type: Text
54+
url = ... # type: Text
55+
base_url = ... # type: Text
56+
url_root = ... # type: Text
57+
host_url = ... # type: Text
58+
host = ... # type: Text
59+
query_string = ... # type: bytes
60+
method = ... # type: Text
6161
def access_route(self): ...
6262
@property
6363
def remote_addr(self) -> str: ...
64-
remote_user = ... # type: unicode
64+
remote_user = ... # type: Text
6565
scheme = ... # type: str
6666
is_xhr = ... # type: bool
6767
is_secure = ... # type: bool
6868
is_multithread = ... # type: bool
6969
is_multiprocess = ... # type: bool
7070
is_run_once = ... # type: bool
7171

72+
_OnCloseT = TypeVar('_OnCloseT', bound=Callable[[], Any])
73+
_SelfT = TypeVar('_SelfT', bound=BaseResponse)
74+
7275
class BaseResponse:
7376
charset = ... # type: str
7477
default_status = ... # type: int
@@ -80,27 +83,26 @@ class BaseResponse:
8083
status_code = ... # type: int
8184
status = ... # type: str
8285
direct_passthrough = ... # type: bool
83-
response = ... # type: Iterable[str]
84-
def __init__(self,
85-
response: Optional[Union[Iterable[str], str]] = ...,
86-
status: Optional[Union[basestring, int]] = ...,
86+
response = ... # type: Iterable[bytes]
87+
def __init__(self, response: Optional[Union[Iterable[bytes], bytes]] = ...,
88+
status: Optional[Union[Text, int]] = ...,
8789
headers: Optional[Union[Headers,
88-
Mapping[basestring, basestring],
89-
Sequence[Tuple[basestring, basestring]]]] = None,
90-
mimetype: Optional[basestring] = ...,
91-
content_type: Optional[basestring] = ...,
92-
direct_passthrough: Optional[bool] = ...) -> None: ...
93-
def call_on_close(self, func): ...
90+
Mapping[Text, Text],
91+
Sequence[Tuple[Text, Text]]]] = ...,
92+
mimetype: Optional[Text] = ...,
93+
content_type: Optional[Text] = ...,
94+
direct_passthrough: bool = ...) -> None: ...
95+
def call_on_close(self, func: _OnCloseT) -> _OnCloseT: ...
9496
@classmethod
95-
def force_type(cls, response, environ=None): ...
97+
def force_type(cls: Type[_SelfT], response: object, environ: Optional[WSGIEnvironment] = ...) -> _SelfT: ...
9698
@classmethod
97-
def from_app(cls, app, environ, buffered=False): ...
98-
def get_data(self, as_text=False): ...
99-
def set_data(self, value): ...
99+
def from_app(cls: Type[_SelfT], app: Any, environ: WSGIEnvironment, buffered: bool = ...) -> _SelfT: ...
100+
def get_data(self, as_text: bool = ...) -> Any: ... # returns bytes if as_text is False (the default), else Text
101+
def set_data(self, value: Union[bytes, Text]) -> None: ...
100102
data = ... # type: Any
101-
def calculate_content_length(self): ...
102-
def make_sequence(self): ...
103-
def iter_encoded(self): ...
103+
def calculate_content_length(self) -> Optional[int]: ...
104+
def make_sequence(self) -> None: ...
105+
def iter_encoded(self) -> Iterator[bytes]: ...
104106
def set_cookie(self, key, value='', max_age=None, expires=None, path='', domain=None, secure=False, httponly=False): ...
105107
def delete_cookie(self, key, path='', domain=None): ...
106108
@property

third_party/3/werkzeug/wrappers.pyi

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime
22
from typing import (
3-
Any, Iterable, Mapping, MutableMapping, Optional, Sequence, Tuple, Type,
4-
Union,
3+
Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Text, Tuple, Type, TypeVar, Union,
54
)
65

76
from wsgiref.types import WSGIEnvironment
@@ -20,7 +19,7 @@ class BaseRequest:
2019
list_storage_class = ... # type: Type
2120
dict_storage_class = ... # type: Type
2221
form_data_parser_class = ... # type: Type
23-
trusted_hosts = ... # type: Optional[Sequence[str]]
22+
trusted_hosts = ... # type: Optional[Sequence[Text]]
2423
disable_data_descriptor = ... # type: Any
2524
environ: WSGIEnvironment = ...
2625
shallow = ... # type: Any
@@ -48,27 +47,30 @@ class BaseRequest:
4847
files = ... # type: MultiDict
4948
cookies = ... # type: TypeConversionDict
5049
headers = ... # type: EnvironHeaders
51-
path = ... # type: str
52-
full_path = ... # type: str
53-
script_root = ... # type: str
54-
url = ... # type: str
55-
base_url = ... # type: str
56-
url_root = ... # type: str
57-
host_url = ... # type: str
58-
host = ... # type: str
50+
path = ... # type: Text
51+
full_path = ... # type: Text
52+
script_root = ... # type: Text
53+
url = ... # type: Text
54+
base_url = ... # type: Text
55+
url_root = ... # type: Text
56+
host_url = ... # type: Text
57+
host = ... # type: Text
5958
query_string = ... # type: bytes
60-
method = ... # type: str
59+
method = ... # type: Text
6160
def access_route(self): ...
6261
@property
6362
def remote_addr(self) -> str: ...
64-
remote_user = ... # type: str
63+
remote_user = ... # type: Text
6564
scheme = ... # type: str
6665
is_xhr = ... # type: bool
6766
is_secure = ... # type: bool
6867
is_multithread = ... # type: bool
6968
is_multiprocess = ... # type: bool
7069
is_run_once = ... # type: bool
7170

71+
_OnCloseT = TypeVar('_OnCloseT', bound=Callable[[], Any])
72+
_SelfT = TypeVar('_SelfT', bound=BaseResponse)
73+
7274
class BaseResponse:
7375
charset = ... # type: str
7476
default_status = ... # type: int
@@ -82,24 +84,24 @@ class BaseResponse:
8284
direct_passthrough = ... # type: bool
8385
response = ... # type: Iterable[bytes]
8486
def __init__(self, response: Optional[Union[Iterable[bytes], bytes]] = ...,
85-
status: Optional[Union[str, int]] = ...,
87+
status: Optional[Union[Text, int]] = ...,
8688
headers: Optional[Union[Headers,
87-
Mapping[str, str],
88-
Sequence[Tuple[str, str]]]]=None,
89-
mimetype: Optional[str] = ...,
90-
content_type: Optional[str] = ...,
89+
Mapping[Text, Text],
90+
Sequence[Tuple[Text, Text]]]] = ...,
91+
mimetype: Optional[Text] = ...,
92+
content_type: Optional[Text] = ...,
9193
direct_passthrough: bool = ...) -> None: ...
92-
def call_on_close(self, func): ...
94+
def call_on_close(self, func: _OnCloseT) -> _OnCloseT: ...
9395
@classmethod
94-
def force_type(cls, response, environ=None): ...
96+
def force_type(cls: Type[_SelfT], response: object, environ: Optional[WSGIEnvironment] = ...) -> _SelfT: ...
9597
@classmethod
96-
def from_app(cls, app, environ, buffered=False): ...
97-
def get_data(self, as_text=False): ...
98-
def set_data(self, value): ...
98+
def from_app(cls: Type[_SelfT], app: Any, environ: WSGIEnvironment, buffered: bool = ...) -> _SelfT: ...
99+
def get_data(self, as_text: bool = ...) -> Any: ... # returns bytes if as_text is False (the default), else Text
100+
def set_data(self, value: Union[bytes, Text]) -> None: ...
99101
data = ... # type: Any
100-
def calculate_content_length(self): ...
101-
def make_sequence(self): ...
102-
def iter_encoded(self): ...
102+
def calculate_content_length(self) -> Optional[int]: ...
103+
def make_sequence(self) -> None: ...
104+
def iter_encoded(self) -> Iterator[bytes]: ...
103105
def set_cookie(self, key, value='', max_age=None, expires=None, path='', domain=None, secure=False, httponly=False): ...
104106
def delete_cookie(self, key, path='', domain=None): ...
105107
@property

0 commit comments

Comments
 (0)