Skip to content

Commit

Permalink
typing: MultiDict.update accepts Iterable Mapping values.
Browse files Browse the repository at this point in the history
MultiDict.__init__ correctly represents it, however the update was
missing the iterable variant.

Also, flipped the order of Iterable[V] and V fixes PyCharm's naive
matching for generics. Mypy would accept both versions, however PyCharm
would only try to infer Mapping V as the List. By listing it second it
will first try to map to the Iterable[V].
  • Loading branch information
MaicoTimmerman committed Jun 2, 2021
1 parent 5098a06 commit 736b811
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -8,6 +8,8 @@ Unreleased
- Handle multiple tokens in ``Connection`` header when routing
WebSocket requests. :issue:`2131`
- Set the debugger pin cookie secure flag when on https. :pr:`2150`
- Fix type annotation for ``MultiDict.update`` to accept iterable values
:pr:`2142`


Version 2.0.1
Expand Down
4 changes: 2 additions & 2 deletions src/werkzeug/datastructures.pyi
Expand Up @@ -115,7 +115,7 @@ class MultiDict(TypeConversionDict[K, V]):
def __init__(
self,
mapping: Optional[
Union[Mapping[K, Union[V, Iterable[V]]], Iterable[Tuple[K, V]]]
Union[Mapping[K, Union[Iterable[V], V]], Iterable[Tuple[K, V]]]
] = None,
) -> None: ...
def __getitem__(self, item: K) -> V: ...
Expand All @@ -141,7 +141,7 @@ class MultiDict(TypeConversionDict[K, V]):
@overload
def to_dict(self, flat: Literal[False]) -> Dict[K, List[V]]: ...
def update( # type: ignore
self, mapping: Union[Mapping[K, V], Iterable[Tuple[K, V]]]
self, mapping: Union[Mapping[K, Union[Iterable[V], V]], Iterable[Tuple[K, V]]]
) -> None: ...
@overload
def pop(self, key: K) -> V: ...
Expand Down

0 comments on commit 736b811

Please sign in to comment.