Fix werkzeug environ type (#1831)

* 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.

* Use Union[str, unicode] for Werkzeug environment keys

This matches the type in wsgiref.types.

* Use WSGIEnvironment from wsgiref.types

* Add '= ...' to environ attribute
This commit is contained in:
Sebastian Rittau
2018-01-26 23:30:23 +01:00
committed by Jelle Zijlstra
parent 66e5863ead
commit a08d57833f
2 changed files with 8 additions and 4 deletions

View File

@@ -2,6 +2,8 @@ from typing import (
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: Mapping[str, object]
environ: WSGIEnvironment = ...
shallow = ... # type: Any
def __init__(self, environ: Mapping[basestring, object], populate_request: bool = ..., shallow: bool = ...) -> None: ...
def __init__(self, environ: WSGIEnvironment, populate_request: bool = ..., shallow: bool = ...) -> None: ...
@property
def url_charset(self) -> str: ...
@classmethod

View File

@@ -2,6 +2,8 @@ from typing import (
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: Mapping[str, object]
environ: WSGIEnvironment = ...
shallow = ... # type: Any
def __init__(self, environ: Mapping[str, object], populate_request: bool = ..., shallow: bool = ...) -> None: ...
def __init__(self, environ: WSGIEnvironment, populate_request: bool = ..., shallow: bool = ...) -> None: ...
@property
def url_charset(self) -> str: ...
@classmethod