4 ms·
>two things that aren't the same type can never be equal Well, actually as long as they implement the right dundermethods, they can totally be.
by coldtea 6y ago
>two things that aren't the same type can never be equal
Well, actually as long as they implement the right dundermethods, they can totally be.
- codethief 6y agoBesides, 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".