[Python-3000] Total ordering and __cmp__

Terry Reedy tjreedy at udel.edu
Wed Mar 21 06:52:02 CET 2007


"Guido van Rossum" <guido at python.org> wrote in message 
news:ca471dc20703201946p722b2ad2q2b4c39e58e12b7d7 at mail.gmail.com...
| 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.

Sorry, leave them out then unless using a mixin.  I was responding to 
Colin's wish that people be able to write one __cmp__ method instead of six 
and thinking about something like what Steven uses but based on __cmp__ 
instead of__key__.  I am not thinking of any use cases at the moment could 
imagine this instead being a cookbook recipe.  Or something to consider if 
there is substantantial objection to the demise of cmp as a alternative to 
keeping it.  But maybe there will not be.

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

A substitute private name for __cmp__ if the latter is to be deprecated 
(and warned about).

Terry Jan Reedy





More information about the Python-3000 mailing list