[Python-3000] Total ordering and __cmp__
Steven Bethard
steven.bethard at gmail.com
Wed Mar 21 06:13:06 CET 2007
On 3/20/07, Steven Bethard <steven.bethard at gmail.com> wrote:
> I've used a __key__() method quite successfully in my own code. Maybe
> we should provide a mixin like::
>
> class KeyedComparisonMixin(object):
> def __eq__(self, other):
> return self.__key__() == other.__key__()
[snip]
> def __ge__(self, other):
> return self.__key__() >= other.__key__()
On 3/20/07, Guido van Rossum <guido at python.org> wrote:
> How would that produce the desired behavior that == and != are defined
> on all objects, but <, <=, >= and > are not?
The intent was that this would be a mixin like DictMixin -- not
default behavior at all. It's roughly parallel to what used to happen
when you defined __cmp__, so anyone that felt that defining __lt__,
__gt__, etc. was too tedious could "opt in" by adding the mixin to
their class bases. I wasn't suggesting that this mixin should ever be
added implicitly by Python.
As far as Python 2.6 code goes, I think simply warning about any uses
of __cmp__ should be fine. (I'd also be nervous about 2to3 generating
something like the code above automatically.)
STeVe
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list