[Python-3000] Total ordering and __cmp__

Guido van Rossum guido at python.org
Wed Mar 21 03:46:28 CET 2007


But can this work? It might end up calling cmp() on two incomparable
objects. For __lt__ etc. that might be the right answer, but for
__eq__ it is *not* -- the default __eq__ and __ne__ *must* compare
object identity.

(What is this __cmp you refer to? A typo for __cmp__ or for cmp?)

--Guido

On 3/20/07, Terry Reedy <tjreedy at udel.edu> wrote:
>
> "Collin Winter" <collinw at gmail.com> wrote in message
> news:43aa6ff70703201810p9d731b8v3497a48539d5dc84 at mail.gmail.com...
> | Quoting from the commit message for r51533, which removed the default
> ordering:
> |
> | What's the status on this? FWIW, I would like to see __cmp__ stay as a
> | fallback measure if __eq__, __ne__, __lt__, etc aren't defined for
> | total ordering purposes. I've run across this while trying to get the
> | docs toolchain working, and I was initially shocked that __cmp__ was
> | no longer called.
>
> An alternative would be to give the object class comparison methods defined
> in terms of a missing __cmp() method.
>
> def __eq__(self,other): return __cmp(self,other) == 0 # etc
>
> This would put the fallback to and conversion of cmp -1,0,1 output in *one*
> place instead of sprinkled everywhere.  Or these could go into a cmp_order
> mixin put in some lib module.
>
> Terry Jan Reedy
>
>
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list