diff --git a/CHANGES.rst b/CHANGES.rst index d4f44162e..728623a78 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/src/werkzeug/datastructures.pyi b/src/werkzeug/datastructures.pyi index f1e650da0..1fcd4f355 100644 --- a/src/werkzeug/datastructures.pyi +++ b/src/werkzeug/datastructures.pyi @@ -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( @@ -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]): diff --git a/src/werkzeug/sansio/response.py b/src/werkzeug/sansio/response.py index 4d55a9ad7..40bdcd8df 100644 --- a/src/werkzeug/sansio/response.py +++ b/src/werkzeug/sansio/response.py @@ -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] diff --git a/src/werkzeug/test.py b/src/werkzeug/test.py index d0ce6f95b..09cb7e89c 100644 --- a/src/werkzeug/test.py +++ b/src/werkzeug/test.py @@ -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]