[Python-3000] Total ordering and cmp (original) (raw)
Steven Bethard steven.bethard at gmail.com
Wed Mar 21 06:13:06 CET 2007
- Previous message: [Python-3000] Total ordering and __cmp__
- Next message: [Python-3000] Total ordering and __cmp__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-3000] Total ordering and __cmp__
- Next message: [Python-3000] Total ordering and __cmp__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]