Skip to content

Commit bb1fb20

Browse files
committed
First step to fix mypy checks for Request
The two ancestors json.JSONMixin and werkzeug.wrappers.Request of cmk.gui.http.Request break mypy checking. For example access to not existing members is not detected anymore. This commit fixes the issue with the json.JSONMixin class. The problem here is that the typesheds distributed with mypy, that are normally available in our virtualenv (lib/python3.7/site-packages/mypy/typeshed/third_party/2and3/werkzeug/wrappers.pyi) miss the typesheds for werkzeug.wrappers.json. I tried hard to add partial typesheds for this single file to tests-py3/typeshed, but did not find a working solution. If you have a good solution, please let me know. I tried to make use of the __getattr__ mechanic added in python/mypy#5231 and the PEP 561 "partial" feature. The only working solution I came up with was copying the original werkzeug typesheds and extending them. Sorry :/. At least it's better than copying the werkzeug.wrappers.json implementation to our code ;). Change-Id: Ie2723ab286188faa67d4738c226462a162552421
1 parent 7524766 commit bb1fb20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3066
-1
lines changed

cmk/gui/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import List, Optional, Any, Iterator, Union, Dict, Text, Tuple # pylint: disable=unused-import
1010
import six
1111
import werkzeug.wrappers
12-
import werkzeug.wrappers.json as json # type: ignore[import]
12+
import werkzeug.wrappers.json as json
1313
from werkzeug.utils import get_content_type
1414

1515
from cmk.utils.encoding import ensure_unicode
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
from types import ModuleType
2+
from typing import Any
3+
4+
from werkzeug import _internal
5+
from werkzeug import datastructures
6+
from werkzeug import debug
7+
from werkzeug import exceptions
8+
from werkzeug import formparser
9+
from werkzeug import http
10+
from werkzeug import local
11+
from werkzeug import security
12+
from werkzeug import serving
13+
from werkzeug import test
14+
from werkzeug import testapp
15+
from werkzeug import urls
16+
from werkzeug import useragents
17+
from werkzeug import utils
18+
from werkzeug import wrappers
19+
from werkzeug import wsgi
20+
21+
class module(ModuleType):
22+
def __getattr__(self, name): ...
23+
def __dir__(self): ...
24+
25+
26+
__version__: Any
27+
28+
run_simple = serving.run_simple
29+
test_app = testapp.test_app
30+
UserAgent = useragents.UserAgent
31+
_easteregg = _internal._easteregg
32+
DebuggedApplication = debug.DebuggedApplication
33+
MultiDict = datastructures.MultiDict
34+
CombinedMultiDict = datastructures.CombinedMultiDict
35+
Headers = datastructures.Headers
36+
EnvironHeaders = datastructures.EnvironHeaders
37+
ImmutableList = datastructures.ImmutableList
38+
ImmutableDict = datastructures.ImmutableDict
39+
ImmutableMultiDict = datastructures.ImmutableMultiDict
40+
TypeConversionDict = datastructures.TypeConversionDict
41+
ImmutableTypeConversionDict = datastructures.ImmutableTypeConversionDict
42+
Accept = datastructures.Accept
43+
MIMEAccept = datastructures.MIMEAccept
44+
CharsetAccept = datastructures.CharsetAccept
45+
LanguageAccept = datastructures.LanguageAccept
46+
RequestCacheControl = datastructures.RequestCacheControl
47+
ResponseCacheControl = datastructures.ResponseCacheControl
48+
ETags = datastructures.ETags
49+
HeaderSet = datastructures.HeaderSet
50+
WWWAuthenticate = datastructures.WWWAuthenticate
51+
Authorization = datastructures.Authorization
52+
FileMultiDict = datastructures.FileMultiDict
53+
CallbackDict = datastructures.CallbackDict
54+
FileStorage = datastructures.FileStorage
55+
OrderedMultiDict = datastructures.OrderedMultiDict
56+
ImmutableOrderedMultiDict = datastructures.ImmutableOrderedMultiDict
57+
escape = utils.escape
58+
environ_property = utils.environ_property
59+
append_slash_redirect = utils.append_slash_redirect
60+
redirect = utils.redirect
61+
cached_property = utils.cached_property
62+
import_string = utils.import_string
63+
dump_cookie = http.dump_cookie
64+
parse_cookie = http.parse_cookie
65+
unescape = utils.unescape
66+
format_string = utils.format_string
67+
find_modules = utils.find_modules
68+
header_property = utils.header_property
69+
html = utils.html
70+
xhtml = utils.xhtml
71+
HTMLBuilder = utils.HTMLBuilder
72+
validate_arguments = utils.validate_arguments
73+
ArgumentValidationError = utils.ArgumentValidationError
74+
bind_arguments = utils.bind_arguments
75+
secure_filename = utils.secure_filename
76+
BaseResponse = wrappers.BaseResponse
77+
BaseRequest = wrappers.BaseRequest
78+
Request = wrappers.Request
79+
Response = wrappers.Response
80+
AcceptMixin = wrappers.AcceptMixin
81+
ETagRequestMixin = wrappers.ETagRequestMixin
82+
ETagResponseMixin = wrappers.ETagResponseMixin
83+
ResponseStreamMixin = wrappers.ResponseStreamMixin
84+
CommonResponseDescriptorsMixin = wrappers.CommonResponseDescriptorsMixin
85+
UserAgentMixin = wrappers.UserAgentMixin
86+
AuthorizationMixin = wrappers.AuthorizationMixin
87+
WWWAuthenticateMixin = wrappers.WWWAuthenticateMixin
88+
CommonRequestDescriptorsMixin = wrappers.CommonRequestDescriptorsMixin
89+
Local = local.Local
90+
LocalManager = local.LocalManager
91+
LocalProxy = local.LocalProxy
92+
LocalStack = local.LocalStack
93+
release_local = local.release_local
94+
generate_password_hash = security.generate_password_hash
95+
check_password_hash = security.check_password_hash
96+
Client = test.Client
97+
EnvironBuilder = test.EnvironBuilder
98+
create_environ = test.create_environ
99+
run_wsgi_app = test.run_wsgi_app
100+
get_current_url = wsgi.get_current_url
101+
get_host = wsgi.get_host
102+
pop_path_info = wsgi.pop_path_info
103+
peek_path_info = wsgi.peek_path_info
104+
SharedDataMiddleware = wsgi.SharedDataMiddleware
105+
DispatcherMiddleware = wsgi.DispatcherMiddleware
106+
ClosingIterator = wsgi.ClosingIterator
107+
FileWrapper = wsgi.FileWrapper
108+
make_line_iter = wsgi.make_line_iter
109+
LimitedStream = wsgi.LimitedStream
110+
responder = wsgi.responder
111+
wrap_file = wsgi.wrap_file
112+
extract_path_info = wsgi.extract_path_info
113+
parse_etags = http.parse_etags
114+
parse_date = http.parse_date
115+
http_date = http.http_date
116+
cookie_date = http.cookie_date
117+
parse_cache_control_header = http.parse_cache_control_header
118+
is_resource_modified = http.is_resource_modified
119+
parse_accept_header = http.parse_accept_header
120+
parse_set_header = http.parse_set_header
121+
quote_etag = http.quote_etag
122+
unquote_etag = http.unquote_etag
123+
generate_etag = http.generate_etag
124+
dump_header = http.dump_header
125+
parse_list_header = http.parse_list_header
126+
parse_dict_header = http.parse_dict_header
127+
parse_authorization_header = http.parse_authorization_header
128+
parse_www_authenticate_header = http.parse_www_authenticate_header
129+
remove_entity_headers = http.remove_entity_headers
130+
is_entity_header = http.is_entity_header
131+
remove_hop_by_hop_headers = http.remove_hop_by_hop_headers
132+
parse_options_header = http.parse_options_header
133+
dump_options_header = http.dump_options_header
134+
is_hop_by_hop_header = http.is_hop_by_hop_header
135+
unquote_header_value = http.unquote_header_value
136+
quote_header_value = http.quote_header_value
137+
HTTP_STATUS_CODES = http.HTTP_STATUS_CODES
138+
url_decode = urls.url_decode
139+
url_encode = urls.url_encode
140+
url_quote = urls.url_quote
141+
url_quote_plus = urls.url_quote_plus
142+
url_unquote = urls.url_unquote
143+
url_unquote_plus = urls.url_unquote_plus
144+
url_fix = urls.url_fix
145+
Href = urls.Href
146+
iri_to_uri = urls.iri_to_uri
147+
uri_to_iri = urls.uri_to_iri
148+
parse_form_data = formparser.parse_form_data
149+
abort = exceptions.Aborter
150+
Aborter = exceptions.Aborter
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import sys
2+
from typing import Any, Optional, Text
3+
4+
if sys.version_info < (3,):
5+
import StringIO as BytesIO
6+
else:
7+
from io import StringIO as BytesIO
8+
9+
PY2: Any
10+
WIN: Any
11+
unichr: Any
12+
text_type: Any
13+
string_types: Any
14+
integer_types: Any
15+
iterkeys: Any
16+
itervalues: Any
17+
iteritems: Any
18+
iterlists: Any
19+
iterlistvalues: Any
20+
int_to_byte: Any
21+
iter_bytes: Any
22+
23+
def fix_tuple_repr(obj): ...
24+
def implements_iterator(cls): ...
25+
def implements_to_string(cls): ...
26+
def native_string_result(func): ...
27+
def implements_bool(cls): ...
28+
29+
range_type: Any
30+
NativeStringIO: Any
31+
32+
def make_literal_wrapper(reference): ...
33+
def normalize_string_tuple(tup): ...
34+
def try_coerce_native(s): ...
35+
36+
wsgi_get_bytes: Any
37+
38+
def wsgi_decoding_dance(s, charset: Text = ..., errors: Text = ...): ...
39+
def wsgi_encoding_dance(s, charset: Text = ..., errors: Text = ...): ...
40+
def to_bytes(x, charset: Text = ..., errors: Text = ...): ...
41+
def to_native(x, charset: Text = ..., errors: Text = ...): ...
42+
def reraise(tp, value, tb: Optional[Any] = ...): ...
43+
44+
imap: Any
45+
izip: Any
46+
ifilter: Any
47+
48+
def to_unicode(x, charset: Text = ..., errors: Text = ..., allow_none_charset: bool = ...): ...
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import Any, Optional
2+
3+
class _Missing:
4+
def __reduce__(self): ...
5+
6+
class _DictAccessorProperty:
7+
read_only: Any
8+
name: Any
9+
default: Any
10+
load_func: Any
11+
dump_func: Any
12+
__doc__: Any
13+
def __init__(self, name, default: Optional[Any] = ..., load_func: Optional[Any] = ..., dump_func: Optional[Any] = ...,
14+
read_only: Optional[Any] = ..., doc: Optional[Any] = ...): ...
15+
def __get__(self, obj, type: Optional[Any] = ...): ...
16+
def __set__(self, obj, value): ...
17+
def __delete__(self, obj): ...
18+
19+
def _easteregg(app: Optional[Any] = ...): ...
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from typing import Any, Optional
2+
3+
class ReloaderLoop:
4+
name: Any
5+
extra_files: Any
6+
interval: float
7+
def __init__(self, extra_files: Optional[Any] = ..., interval: float = ...): ...
8+
def run(self): ...
9+
def restart_with_reloader(self): ...
10+
def trigger_reload(self, filename): ...
11+
def log_reload(self, filename): ...
12+
13+
class StatReloaderLoop(ReloaderLoop):
14+
name: Any
15+
def run(self): ...
16+
17+
class WatchdogReloaderLoop(ReloaderLoop):
18+
observable_paths: Any
19+
name: Any
20+
observer_class: Any
21+
event_handler: Any
22+
should_reload: Any
23+
def __init__(self, *args, **kwargs): ...
24+
def trigger_reload(self, filename): ...
25+
def run(self): ...
26+
27+
reloader_loops: Any
28+
29+
def run_with_reloader(main_func, extra_files: Optional[Any] = ..., interval: float = ..., reloader_type: str = ...): ...

tests-py3/typeshed/werkzeug/contrib/__init__.pyi

Whitespace-only changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from typing import Any, Optional
2+
3+
XHTML_NAMESPACE: Any
4+
5+
def format_iso8601(obj): ...
6+
7+
class AtomFeed:
8+
default_generator: Any
9+
title: Any
10+
title_type: Any
11+
url: Any
12+
feed_url: Any
13+
id: Any
14+
updated: Any
15+
author: Any
16+
icon: Any
17+
logo: Any
18+
rights: Any
19+
rights_type: Any
20+
subtitle: Any
21+
subtitle_type: Any
22+
generator: Any
23+
links: Any
24+
entries: Any
25+
def __init__(self, title: Optional[Any] = ..., entries: Optional[Any] = ..., **kwargs): ...
26+
def add(self, *args, **kwargs): ...
27+
def generate(self): ...
28+
def to_string(self): ...
29+
def get_response(self): ...
30+
def __call__(self, environ, start_response): ...
31+
32+
class FeedEntry:
33+
title: Any
34+
title_type: Any
35+
content: Any
36+
content_type: Any
37+
url: Any
38+
id: Any
39+
updated: Any
40+
summary: Any
41+
summary_type: Any
42+
author: Any
43+
published: Any
44+
rights: Any
45+
links: Any
46+
categories: Any
47+
xml_base: Any
48+
def __init__(self, title: Optional[Any] = ..., content: Optional[Any] = ..., feed_url: Optional[Any] = ..., **kwargs): ...
49+
def generate(self): ...
50+
def to_string(self): ...
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from typing import Any, Optional
2+
3+
class BaseCache:
4+
default_timeout: float
5+
def __init__(self, default_timeout: float = ...): ...
6+
def get(self, key): ...
7+
def delete(self, key): ...
8+
def get_many(self, *keys): ...
9+
def get_dict(self, *keys): ...
10+
def set(self, key, value, timeout: Optional[float] = ...): ...
11+
def add(self, key, value, timeout: Optional[float] = ...): ...
12+
def set_many(self, mapping, timeout: Optional[float] = ...): ...
13+
def delete_many(self, *keys): ...
14+
def has(self, key): ...
15+
def clear(self): ...
16+
def inc(self, key, delta=...): ...
17+
def dec(self, key, delta=...): ...
18+
19+
class NullCache(BaseCache): ...
20+
21+
class SimpleCache(BaseCache):
22+
clear: Any
23+
def __init__(self, threshold: int = ..., default_timeout: float = ...): ...
24+
def get(self, key): ...
25+
def set(self, key, value, timeout: Optional[float] = ...): ...
26+
def add(self, key, value, timeout: Optional[float] = ...): ...
27+
def delete(self, key): ...
28+
def has(self, key): ...
29+
30+
class MemcachedCache(BaseCache):
31+
key_prefix: Any
32+
def __init__(self, servers: Optional[Any] = ..., default_timeout: float = ..., key_prefix: Optional[Any] = ...): ...
33+
def get(self, key): ...
34+
def get_dict(self, *keys): ...
35+
def add(self, key, value, timeout: Optional[float] = ...): ...
36+
def set(self, key, value, timeout: Optional[float] = ...): ...
37+
def get_many(self, *keys): ...
38+
def set_many(self, mapping, timeout: Optional[float] = ...): ...
39+
def delete(self, key): ...
40+
def delete_many(self, *keys): ...
41+
def has(self, key): ...
42+
def clear(self): ...
43+
def inc(self, key, delta=...): ...
44+
def dec(self, key, delta=...): ...
45+
def import_preferred_memcache_lib(self, servers): ...
46+
47+
GAEMemcachedCache: Any
48+
49+
class RedisCache(BaseCache):
50+
key_prefix: Any
51+
def __init__(self, host: str = ..., port: int = ..., password: Optional[Any] = ..., db: int = ...,
52+
default_timeout: float = ..., key_prefix: Optional[Any] = ..., **kwargs): ...
53+
def dump_object(self, value): ...
54+
def load_object(self, value): ...
55+
def get(self, key): ...
56+
def get_many(self, *keys): ...
57+
def set(self, key, value, timeout: Optional[float] = ...): ...
58+
def add(self, key, value, timeout: Optional[float] = ...): ...
59+
def set_many(self, mapping, timeout: Optional[float] = ...): ...
60+
def delete(self, key): ...
61+
def delete_many(self, *keys): ...
62+
def has(self, key): ...
63+
def clear(self): ...
64+
def inc(self, key, delta=...): ...
65+
def dec(self, key, delta=...): ...
66+
67+
class FileSystemCache(BaseCache):
68+
def __init__(self, cache_dir, threshold: int = ..., default_timeout: float = ..., mode: int = ...): ...
69+
def clear(self): ...
70+
def get(self, key): ...
71+
def add(self, key, value, timeout: Optional[float] = ...): ...
72+
def set(self, key, value, timeout: Optional[float] = ...): ...
73+
def delete(self, key): ...
74+
def has(self, key): ...
75+
76+
class UWSGICache(BaseCache):
77+
cache: Any
78+
def __init__(self, default_timeout: float = ..., cache: str = ...): ...
79+
def get(self, key): ...
80+
def delete(self, key): ...
81+
def set(self, key, value, timeout: Optional[float] = ...): ...
82+
def add(self, key, value, timeout: Optional[float] = ...): ...
83+
def clear(self): ...
84+
def has(self, key): ...

0 commit comments

Comments
 (0)