Python Schoolby trefilov
Шаг 1 из 4+130 XP

typing.Protocol — структурная типизация

Duck typing с типами.

Protocol

from typing import Protocol
class Greetable(Protocol):
    def greet(self) -> str: ...
def hi(x: Greetable) -> str:
    return x.greet()