How the magic of
When you call
x == y, Python first calls
x.__eq__(y). This would not help us
much, because we would have to keep an eye on order of the arguments when
DirtyEquals objects. But that's where were another feature of
Python comes in.
x.__eq__(y) returns the
NotImplemented object, then Python will try to
y.__eq__(x). Objects in the standard library return that value when they
don't know how to compare themselves to objects of
type(y) (Without checking
the C source I can't be certain if this assumption holds for all classes, but it
works for all the basic ones).
you can see an example how that is implemented in Python.
By default, object implements
NotImplementedin the case of a false comparison:
True if x is y else NotImplemented.
See the Python documentation for more information (