If you look at the description of the rich comparison methods in the documentation: http://docs.python.org/reference/datamodel.html#object.__lt__
It refers to a recipe: http://code.activestate.com/recipes/576529/ However, that recipe will convert a __ge__(self, other) into a other < self. So when you call self <= other, you'll end up calling other < self. So far, so good. But, the problem is another piece of text: "A rich comparison method may return the singleton NotImplemented if it does not implement the operation for a given pair of arguments. " If you do this, what happens is that Python will try to swap the parameters around, so it will convert a self < other into a other <= self. And here we see the problem. If class A returns NotImplemented when compared to class B, and class B implements the recipe above, then we get infinite recursion, because 1. A() < B() will call A.__lt__(B) which will return NotImplemented. 2. which will mean that Python calls B.__ge__(A) 3. Which B implements by doing A < B 4. Start over at 1. Have I missed something, or is this recipe incomplete by not handling the NotImplemented case? If it is, I think the recipe should be changed to something that handles it. -- Lennart Regebro: http://regebro.wordpress.com/ Python 3 Porting: http://python-incompatibility.googlecode.com/ +33 661 58 14 64 _______________________________________________ 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