2 ms·
Besides, there is a difference between the actual type of the objects `a` and `b` in `a == b` and the structural type you specify in an annotation. For instanc
by codethief 6y ago
Besides, there is a difference between the actual type of the objects `a` and `b` in `a == b` and the structural type you specify in an annotation.
For instance:
from typing import Protocol
class MyClass:
def method_a(self) -> None:
...
def method_b(self) -> None:
...
class ProtocolA(Protocol):
def method_a(self) -> None:
...
class ProtocolB(Protocol):
def method_b(self) -> None:
...
def compare(a: ProtocolA, b: ProtocolB):
if a == b:
print("a == b")
else:
print("a != b")
a = MyClass()
b = MyClass()
compare(a, b)
Clearly, you would expect the output to be "a == b".