Paul Moore wrote: > 2009/4/3 R. David Murray <rdmurray at 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 | ncoghlan at gmail.com | Brisbane, Australia ---------------------------------------------------------------
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4