You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No structural typing for mapping inside KeysView, ValuesView and ItemsView #14555
Maybe it's intended to be like that, but if some class implements all the necessary methods for KeysView, ValuesView or ItemsView, mypy will generate errors, although python code will work:
$ mypy t.pyt.py:20: error: Need type annotation for "keys" [var-annotated]t.py:20: error: Argument 1 to "KeysView" has incompatible type "Map[int, int]"; expected "Mapping[Never, Any]" [arg-type]t.py:21: error: Need type annotation for "values" [var-annotated]t.py:21: error: Argument 1 to "ValuesView" has incompatible type "Map[int, int]"; expected "Mapping[Any, Never]" [arg-type]t.py:22: error: Need type annotation for "items" [var-annotated]t.py:22: error: Argument 1 to "ItemsView" has incompatible type "Map[int, int]"; expected "Mapping[Never, Never]" [arg-type]Found 6 errors in 1 file (checked 1 source file)
$ python3 t.py[3]1
In my case I couldn't add multiple inheritance with Mapping because of metaclass conflict
Unfortunately, we use Mapping quite extensively in typeshed, where a proper (tighter) protocol would be more appropriate. Any PRs to improve the situation are welcome!
Activity
srittau commentedon Aug 11, 2025
Unfortunately, we use
Mappingquite extensively in typeshed, where a proper (tighter) protocol would be more appropriate. Any PRs to improve the situation are welcome!