Type annotations for SharedDataMiddleware produce mypy errors in common circumstances #2958
Closed
Description
werkzeug/src/werkzeug/middleware/shared_data.py
Lines 102 to 113 in 5add63c
exports
is annotated as dict[str, str | tuple[str, str]]
(plus the iterable case). Because dict
is invariant, passing a simple dict[str, str]
actually produces a mypy error! Users can work around this by manually annotating the data as dict[str, str | tuple[str, str]]
, but this is very unergonomic.
https://mypy-play.net/?mypy=latest&python=3.12&gist=7194ebea2b603890033453b8d735e232 is a minimal demonstration of this issue, and the recommended workaround: annotating the value as collections.Mapping
instead.
Metadata
Assignees
Labels
No labels