Код: Выделить всё
from typing import Protocol
class A(Protocol):
def foo(self) -> str: ...
class B:
pass
Код: Выделить всё
x: A = B()
Код: Выделить всё
mypy .
error: Incompatible types in assignment (expression has type "B", variable has type "A")
Код: Выделить всё
class A(Protocol):
def foo(self) -> str: ...
class B(models.Model):
pass
x: A = B()
Кто-нибудь знает, что здесь, и у вас есть совет, как заставить mypy проверить, реализует ли модель Django протокол? Обратите внимание: я бы предпочел, чтобы модель не требовала явного подкласса протокола.
Подробнее здесь: https://stackoverflow.com/questions/770 ... ngo-models