For example, we have a class:
class A:
def send(msg: bytes) -> None:
# implementation...
pass
def recv(n: int) -> bytes:
# implementation
pass
and a function:
def a(obj, n: int) -> None:
received = obj.recv(n)
obj.send(received)
It's fairly obvious, that not only instances of class A can be passed as the obj argument, but also instances of socket.socket, maybe other classes, which have recv and send implemented.
How can one annotate/type hint obj argument, so that it says something like:
obj type must possess methods send and recv
send method must be of type Callable[[bytes], None]
recv method must be of type Callable[[int], bytes]