From 17b6b5efe99cbad1eb01aa7630143b8c237ea7e3 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 15 Nov 2017 00:05:31 +0100 Subject: [PATCH 1/4] Fix werkzeug environ type PEP 3333 explicitly calls for environ to be a built-in dict. Using a Mapping will not only prevent the dict from being modified (which is explicitly allowed by PEP 3333), it will also cause interaction problems when the environment is passed to other WSGI handlers. Also change the value type from object to Any for convenience. By definition, the values can be anything and can't be type checked. Using object instead of Any forces us to explicitly cast the value whenever we access it. --- third_party/2/werkzeug/wrappers.pyi | 6 +++--- third_party/3/werkzeug/wrappers.pyi | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/third_party/2/werkzeug/wrappers.pyi b/third_party/2/werkzeug/wrappers.pyi index e43aa703fef1..df629276ea02 100644 --- a/third_party/2/werkzeug/wrappers.pyi +++ b/third_party/2/werkzeug/wrappers.pyi @@ -1,5 +1,5 @@ from typing import ( - Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, + Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, Dict, ) from .datastructures import ( @@ -18,9 +18,9 @@ class BaseRequest: form_data_parser_class = ... # type: Type trusted_hosts = ... # type: Optional[Sequence[unicode]] disable_data_descriptor = ... # type: Any - environ = ... # type: Mapping[str, object] + environ = ... # type: Dict[str, Any] shallow = ... # type: Any - def __init__(self, environ: Mapping[basestring, object], populate_request: bool = ..., shallow: bool = ...) -> None: ... + def __init__(self, environ: Dict[str, Any], populate_request: bool = ..., shallow: bool = ...) -> None: ... @property def url_charset(self) -> str: ... @classmethod diff --git a/third_party/3/werkzeug/wrappers.pyi b/third_party/3/werkzeug/wrappers.pyi index 4d31a9100c1b..e4db7a582c94 100644 --- a/third_party/3/werkzeug/wrappers.pyi +++ b/third_party/3/werkzeug/wrappers.pyi @@ -1,5 +1,5 @@ from typing import ( - Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, + Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, Dict, ) from .datastructures import ( @@ -18,9 +18,9 @@ class BaseRequest: form_data_parser_class = ... # type: Type trusted_hosts = ... # type: Optional[Sequence[str]] disable_data_descriptor = ... # type: Any - environ = ... # type: Mapping[str, object] + environ = ... # type: Dict[str, Any] shallow = ... # type: Any - def __init__(self, environ: Mapping[str, object], populate_request: bool = ..., shallow: bool = ...) -> None: ... + def __init__(self, environ: Dict[str, Any], populate_request: bool = ..., shallow: bool = ...) -> None: ... @property def url_charset(self) -> str: ... @classmethod From b91ae9c3c71115d78d9bdaee324fa47b6f2780b7 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 15 Nov 2017 00:20:51 +0100 Subject: [PATCH 2/4] Use Union[str, unicode] for Werkzeug environment keys This matches the type in wsgiref.types. --- third_party/2/werkzeug/wrappers.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/2/werkzeug/wrappers.pyi b/third_party/2/werkzeug/wrappers.pyi index df629276ea02..dae11c0cfdc4 100644 --- a/third_party/2/werkzeug/wrappers.pyi +++ b/third_party/2/werkzeug/wrappers.pyi @@ -18,9 +18,9 @@ class BaseRequest: form_data_parser_class = ... # type: Type trusted_hosts = ... # type: Optional[Sequence[unicode]] disable_data_descriptor = ... # type: Any - environ = ... # type: Dict[str, Any] + environ = ... # type: Dict[Union[str, unicode], Any] shallow = ... # type: Any - def __init__(self, environ: Dict[str, Any], populate_request: bool = ..., shallow: bool = ...) -> None: ... + def __init__(self, environ: Dict[Union[str, unicode], Any], populate_request: bool = ..., shallow: bool = ...) -> None: ... @property def url_charset(self) -> str: ... @classmethod From 59634caea49632538132a4bfdeb0ba4b0fd5cdc4 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 18 Jan 2018 17:04:12 +0100 Subject: [PATCH 3/4] Use WSGIEnvironment from wsgiref.types --- third_party/2/werkzeug/wrappers.pyi | 8 +++++--- third_party/3/werkzeug/wrappers.pyi | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/third_party/2/werkzeug/wrappers.pyi b/third_party/2/werkzeug/wrappers.pyi index dae11c0cfdc4..abbe6c973729 100644 --- a/third_party/2/werkzeug/wrappers.pyi +++ b/third_party/2/werkzeug/wrappers.pyi @@ -1,7 +1,9 @@ from typing import ( - Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, Dict, + Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, ) +from wsgiref.types import WSGIEnvironment + from .datastructures import ( CombinedMultiDict, EnvironHeaders, Headers, ImmutableMultiDict, MultiDict, TypeConversionDict, @@ -18,9 +20,9 @@ class BaseRequest: form_data_parser_class = ... # type: Type trusted_hosts = ... # type: Optional[Sequence[unicode]] disable_data_descriptor = ... # type: Any - environ = ... # type: Dict[Union[str, unicode], Any] + environ: WSGIEnvironment shallow = ... # type: Any - def __init__(self, environ: Dict[Union[str, unicode], Any], populate_request: bool = ..., shallow: bool = ...) -> None: ... + def __init__(self, environ: WSGIEnvironment, populate_request: bool = ..., shallow: bool = ...) -> None: ... @property def url_charset(self) -> str: ... @classmethod diff --git a/third_party/3/werkzeug/wrappers.pyi b/third_party/3/werkzeug/wrappers.pyi index e4db7a582c94..13bd9f2b30ba 100644 --- a/third_party/3/werkzeug/wrappers.pyi +++ b/third_party/3/werkzeug/wrappers.pyi @@ -1,7 +1,9 @@ from typing import ( - Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, Dict, + Any, Iterable, Mapping, Optional, Sequence, Tuple, Type, Union, ) +from wsgiref.types import WSGIEnvironment + from .datastructures import ( CombinedMultiDict, EnvironHeaders, Headers, ImmutableMultiDict, MultiDict, TypeConversionDict, @@ -18,9 +20,9 @@ class BaseRequest: form_data_parser_class = ... # type: Type trusted_hosts = ... # type: Optional[Sequence[str]] disable_data_descriptor = ... # type: Any - environ = ... # type: Dict[str, Any] + environ: WSGIEnvironment shallow = ... # type: Any - def __init__(self, environ: Dict[str, Any], populate_request: bool = ..., shallow: bool = ...) -> None: ... + def __init__(self, environ: WSGIEnvironment, populate_request: bool = ..., shallow: bool = ...) -> None: ... @property def url_charset(self) -> str: ... @classmethod From 929b7cc4a89249fac6a9022c13f07438c669280e Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 19 Jan 2018 15:52:13 +0100 Subject: [PATCH 4/4] Add '= ...' to environ attribute --- third_party/2/werkzeug/wrappers.pyi | 2 +- third_party/3/werkzeug/wrappers.pyi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/2/werkzeug/wrappers.pyi b/third_party/2/werkzeug/wrappers.pyi index abbe6c973729..9ab9eb5d6d35 100644 --- a/third_party/2/werkzeug/wrappers.pyi +++ b/third_party/2/werkzeug/wrappers.pyi @@ -20,7 +20,7 @@ class BaseRequest: form_data_parser_class = ... # type: Type trusted_hosts = ... # type: Optional[Sequence[unicode]] disable_data_descriptor = ... # type: Any - environ: WSGIEnvironment + environ: WSGIEnvironment = ... shallow = ... # type: Any def __init__(self, environ: WSGIEnvironment, populate_request: bool = ..., shallow: bool = ...) -> None: ... @property diff --git a/third_party/3/werkzeug/wrappers.pyi b/third_party/3/werkzeug/wrappers.pyi index 13bd9f2b30ba..594145379851 100644 --- a/third_party/3/werkzeug/wrappers.pyi +++ b/third_party/3/werkzeug/wrappers.pyi @@ -20,7 +20,7 @@ class BaseRequest: form_data_parser_class = ... # type: Type trusted_hosts = ... # type: Optional[Sequence[str]] disable_data_descriptor = ... # type: Any - environ: WSGIEnvironment + environ: WSGIEnvironment = ... shallow = ... # type: Any def __init__(self, environ: WSGIEnvironment, populate_request: bool = ..., shallow: bool = ...) -> None: ... @property