[Python-ideas] Automatic comparisons by default

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Mar 16 01:26:11 CET 2011


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).

2) There are fallbacks from the individual methods to
__cmp__, but *not* in the other direction.

-- 
Greg



More information about the Python-ideas mailing list