Код: Выделить всё
class A:
def f(self, a: int) -> int:
raise NotImplementedError
class B(A):
def f(self, a):
return a
Код: Выделить всё
class B(A):
def f(self, a: bool) -> str:
return str(a)
< /code>
error: Return type "str" of "f" incompatible with return type "int" in supertype "A" [override]
error: Argument 1 of "f" is incompatible with supertype "A"; supertype defines the argument type as "int" [override]
note: This violates the Liskov substitution principle
note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
< /code>
Since mypy already knows the expected types of B.f
Подробнее здесь: https://stackoverflow.com/questions/797 ... ent-method