Skip to content

Commit

Permalink
Fix type-hint in CallbackDict
Browse files Browse the repository at this point in the history
  • Loading branch information
Yourun-proger authored and pgjones committed Sep 23, 2021
1 parent 0e9160b commit 366b2d9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -34,6 +34,8 @@ Unreleased
- Ad-hoc TLS certs are generated with SAN matching CN. :issue:`2158`
- Fix memory usage for locals when using Python 3.6 or pre 0.4.17
greenlet versions. :pr:`2212`
- Fix type anntoation in ``CallbackDict``, because it is not
utilizing a bound TypeVar. :issue:`2235`


Version 2.0.1
Expand Down
3 changes: 2 additions & 1 deletion src/werkzeug/datastructures.pyi
Expand Up @@ -29,6 +29,7 @@ K = TypeVar("K")
V = TypeVar("V")
T = TypeVar("T")
D = TypeVar("D")
_CD = TypeVar("_CD", bound="CallbackDict")

def is_immutable(self: object) -> NoReturn: ...
def iter_multi_items(
Expand Down Expand Up @@ -685,7 +686,7 @@ class CallbackDict(UpdateDictMixin[K, V], Dict[K, V]):
def __init__(
self,
initial: Optional[Union[Mapping[K, V], Iterable[Tuple[K, V]]]] = None,
on_update: Optional[Callable[[CallbackDict], None]] = None,
on_update: Optional[Callable[[_CD], None]] = None,
) -> None: ...

class HeaderSet(Set[str]):
Expand Down
2 changes: 1 addition & 1 deletion src/werkzeug/sansio/response.py
Expand Up @@ -316,7 +316,7 @@ def mimetype_params(self) -> t.Dict[str, str]:
.. versionadded:: 0.5
"""

def on_update(d: t.Dict[str, str]) -> None:
def on_update(d: CallbackDict) -> None:
self.headers["Content-Type"] = dump_options_header(self.mimetype, d)

d = parse_options_header(self.headers.get("content-type", ""))[1]
Expand Down
2 changes: 1 addition & 1 deletion src/werkzeug/test.py
Expand Up @@ -570,7 +570,7 @@ def mimetype_params(self) -> t.Mapping[str, str]:
.. versionadded:: 0.14
"""

def on_update(d: t.Mapping[str, str]) -> None:
def on_update(d: CallbackDict) -> None:
self.headers["Content-Type"] = dump_options_header(self.mimetype, d)

d = parse_options_header(self.headers.get("content-type", ""))[1]
Expand Down

0 comments on commit 366b2d9

Please sign in to comment.