Код: Выделить всё
from typing import Protocol, runtime_checkable
@runtime_checkable
class A(Protocol):
def f(self): ...
class B:
def f(self): ...
if __name__ == '__main__':
assert isinstance(B(), A)
Код: Выделить всё
TypeError: Instance and class checks can only be used with @runtime_checkable protocols
Код: Выделить всё
class A(Protocol):
x: int
def f(self): ...
Код: Выделить всё
>>> assert isinstance(B(), A)
Traceback (most recent call last):
File "", line 1, in
AssertionError
Подробнее здесь: https://stackoverflow.com/questions/799 ... -checkable
Мобильная версия