Код: Выделить всё
from collections.abc import Mapping
def my_fn(m: Mapping[str | int, str]):
print(m)
d = {"a": "b"}
my_fn(d)
Код: Выделить всё
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>
Почему это так? Я понимаю, почему назначение DICT [str, str]
Подробнее здесь: https://stackoverflow.com/questions/797 ... g-key-type