[Python-3000] Please re-add __cmp__ to python 3000

Adam Olsen rhamph at gmail.com
Tue Oct 30 02:36:14 CET 2007


On 10/29/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Adam Olsen wrote:
> > It's not clear to me how many distinct operations you'd need though,
> > or how acceptable reflections would be.
>
> My intention was just to directly expose the tp_richcmp
> slot, so there would be six.
>
> To make things easier in the common case, there could
> perhaps be a utility function that would take a comparison
> operation code and a -1, 0, 1 value and return the
> appropriate boolean. Then a __richcmp__ method could be
> written very similarly to the way a __cmp__ method is
> now. It might even be possible for 2to3 to convert
> __cmp__ methods to __richcmp__ methods automatically.

It'd be simpler still if we only had __cmp__ and __eq__.  I just don't
understand the use cases where that's not sufficient.

Hrm.  I guess set's subset checking requires more relationships than
__cmp__ provides.  Abandoning that feature probably isn't an option,
so nevermind me.

(Although, if we really wanted we could use -2/+2 to mean
subset/superset, while -1/+1 mean smaller/larger.)

-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list