__cmp__ used to provide a convenient way to make all ordering operators work by defining a single method. For better or worse, it's gone in 3.0.<br><br>To provide total ordering without __cmp__ one has to implement all of __lt__, __gt__, __le__, __ge__, __eq__ and __ne__. However, in all but a few cases it suffices only to provide a "real" implementation for e.g. __lt__ and define all the other methods in terms of it as follows:<br>
<br>class TotalOrderMixin(object):<br> def __lt__(self, other):<br> raise NotImplemented # override this<br><br> def __gt__(self, other):<br> return other < self<br><br> def __le__(self, other):<br>
return not (other < self)<br><br> def __ge__(self, other):<br> return not (self < other)<br><br>__eq__ and __ne__ are somewhat special, although it is possible to define them in terms of __lt__<br>
<br> def __eq__(self, other):<br> return not (self == other)<br><br> def __ne__(self, other):<br> return self < other or other < self<br><br>it may be inefficient.<br><br>So, to avoid the situation where all the projects that match <a href="http://www.google.com/codesearch?q=__cmp__+lang%3Apython">http://www.google.com/codesearch?q=__cmp__+lang%3Apython</a> have to implement their own TotalOrderMixin, perhaps one could be provided in the stdlib? Or even better, shouldn't a class grow automagic __gt__, __le__, __ge__ if __lt__ is provided, and, in a similar vein, __ne__ if __eq__ is provided?<br>