[Python-ideas] Automatic comparisons by default

Steven D'Aprano steve at pearwood.info
Wed Mar 16 14:37:35 CET 2011

Greg Ewing wrote:
> Raymond Hettinger wrote:
>> It's a little more complicated than "if Python doesn't find ...".
>> In Python 3, object() already has __le,__, __gt__, __ge__, and __gt__,
>> so those methods always get found.
> This whole mess makes me think it was a mistake to throw
> out __cmp__ in its entirety.
> The relationship between __cmp__ and the other methods
> was tricky under the old scheme because there were fallbacks
> in both directions. But I think it should be possible to
> come up with a new scheme that's well-behaved based on
> the following ideas:
> 1) __cmp__ returns one of four possible results: LessThan,
> EqualTo, GreaterThan or NotEqual (the latter for unordered
> types).

Wouldn't that last one be better called Unordered rather than NotEqual? 
More explicit and less likely to fool people into assuming total 
ordering ("NotEqual, that implies one of LessThan or GreaterThan, right?").

And shouldn't there be provision for __cmp__ to return NotImplemented, 
as rich comparison methods currently do, so as to allow the other 
operand to have a say?


More information about the Python-ideas mailing list