Код: Выделить всё
from collections.abc import Mapping
class Parent:
pass
class Child(Parent):
pass
assert issubclass(Child, Parent)
def takes_mapping(mapping: Mapping[Parent, int]):
return
child = Child()
my_dict: dict[Child, int] = {child: 1}
my_mapping: Mapping[Child, int] = {child: 1}
takes_mapping(my_dict) # typing error...
takes_mapping(my_mapping) # same basic error, involving invariance (see below)
Код: Выделить всё
Argument of type "dict[Child, int]" cannot be assigned to parameter "mapping" of type "Mapping[Parent, int]" in function "takes_mapping"
"dict[Child, int]" is not assignable to "Mapping[Parent, int]"
Type parameter "_KT@Mapping" is invariant, but "Child" is not the same as "Parent" reportArgumentType
Подробнее здесь: https://stackoverflow.com/questions/791 ... -in-python
Мобильная версия