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
Subtype of mapping is not compatible type in .update() method #10970
This code (taken from aioredis) produces this error: error: Argument 1 to "update" of "dict" has incompatible type "Dict[str, Callable[[Dict[str, str]], None]]"; expected "Mapping[Union[bytes, str, memoryview], Optional[Callable[[Dict[str, str]], None]]]" [arg-type]
But, the types are compatible as the keys and values are part of the expected union, I can't think of any operation that would make this unsafe. I understand it could be unsafe if the expectation was MutableMapping, as the function might assign any of the unioned types, but for Mapping this looks completely safe to me.
Think that's a different issue. It doesn't recognise that Tuple[int, int] is compatible with Tuple[int, ...]. I don't think it has anything to do with Mapping.
You can just add an annotation to make it work: Y: Dict[Tuple[int, ...], int]
Although interesting that it accepts ItemsView[Tuple[int, int], ...], but not Dict[Tuple[int, int], ...]... Maybe it is related...
Activity
JelleZijlstra commentedon Aug 11, 2021
For reference,
dict.updateis defined in typeshed as:I need to think about this more but I guess it has to do with the invariant key type argument to
Mapping.Dreamsorcerer commentedon Aug 21, 2021
For reference, errors come from this file: https://github.com/aio-libs/aioredis-py/blob/f5a8e80882c3dfa70cf9cc2e44d110faeb579d74/aioredis/client.py
Just search for the issue number (10970) to find them.
mzapotoczny commentedon Nov 9, 2021
I stumbled across similar problem.
causes
while if we use other
updatedefinition:mypy passes.
Dreamsorcerer commentedon Nov 9, 2021
Think that's a different issue. It doesn't recognise that
Tuple[int, int]is compatible withTuple[int, ...]. I don't think it has anything to do withMapping.You can just add an annotation to make it work:
Y: Dict[Tuple[int, ...], int]Although interesting that it accepts
ItemsView[Tuple[int, int], ...], but notDict[Tuple[int, int], ...]... Maybe it is related...Dreamsorcerer commentedon Jul 14, 2025
Annotations seem to have changed to expect SupportsKeysAndGetItem, but otherwise this error still seems reproducible.