fork download
  1. class A(object):
  2. def __init__(self, a, b):
  3. self._a = a
  4. self._b = b
  5.  
  6. def __eq__(self, other):
  7. print("a eq")
  8. return (self._a, self._b) == (other._a, other._b)
  9.  
  10. class B(A):
  11. def __eq__(self, other):
  12. print("b eq")
  13. return isinstance(other, B) and super(B, self).__eq__(other)
  14.  
  15. a = A(1, 2)
  16. b = B(1, 2)
  17. print(a == b)
  18. print(b == a)
  19.  
Success #stdin #stdout 0.01s 7292KB
stdin
Standard input is empty
stdout
b eq
False
b eq
False