[Python-ideas] Automatic comparisons by default

Doug Hellmann doug.hellmann at gmail.com
Thu Mar 17 01:03:19 CET 2011

On Mar 16, 2011, at 5:48 PM, Masklinn wrote:

> On 2011-03-16, at 22:40 , Doug Hellmann wrote:
>> On Mar 15, 2011, at 2:47 PM, Guido van Rossum wrote:
>>> On Tue, Mar 15, 2011 at 11:03 AM, Facundo Batista
>>> <facundobatista at gmail.com> wrote:
>>>> Two very related proposals:
>>>> 1. On "!=", if Python doesn't find __ne__, use "not __eq__()".
>>> +1 on this one. I cannot count how often I have written a base class
>>> for this sole purpose. And I cannot think of any cases where it would
>>> be the wrong thing, *except* those damn IEEE NaNs (which we can
>>> special-case).
>>>> 2. On "<=", if Python doesn't find __le__, use "__eq__() or __lt__()".
>>>> The same for ">=", of course.
>>> Big -1 for this. Inequalities (orderings) are much more subtle than
>>> equalities. See e.g. sets.
>>> I'd be okay with offering a standard base class to supply this (#2)
>>> behavior though.
>> The functools.total_ordering class decorator fills in the gaps, right?
> What is it doing in functools? I thought functools was for higher-order functions (so functions manipulating functions), shouldn't something like a class decorator be in a classtools/typetools module?
> (also, since I apparently completely missed this, what was the rationale of making it a class decorator rather than, say, a mixin?)

I couldn't really say. I just found it, I didn't put it there. :-)


More information about the Python-ideas mailing list