Code: Select all
from collections.abc import Mapping
def my_fn(m: Mapping[str | int, str]):
print(m)
d = {"a": "b"}
my_fn(d)
Code: Select all
error: Argument of type "dict[str, str]" cannot be assigned to parameter "m" of type "Mapping[str | int, str]" in function "my_fn"
"dict[str, str]" is not assignable to "Mapping[str | int, str]"
Type parameter "_KT@Mapping" is invariant, but "str" is not the same as "str | int" (reportArgumentType)
< /code>
Warum ist dies der Fall? Ich verstehe, warum das Zuweisen von DICT [STR, STR]