Paul Moore wrote: > 2009/4/3 R. David Murray <rdmur...@bitdance.com>: >> a == b >> >> So, python calls a.__eq__(b) >> >> Now, that function does: >> >> a.key == b >> >> Since b is an object with an __eq__ method, python calls >> b.__eq__(a.key). > > That's the bit I can't actually find documented anywhere.
It doesn't quite work the way RDM desribed it - he missed a step. a == b So, python calls a.__eq__(b) Now, that function does: a.key == b which first calls a.key.__eq__(b) # This step was missing Since str has no idea what an Element is, that returns NotImplemented. Since __eq__ is defined as being commutative, the interpreter then tries b.__eq__(a.key). That function does: b.key == a.key which calls b.key.__eq__(a.key) which is a well defined string comparison and returns the expected answer. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com