[Python-ideas] Automatic comparisons by default

Masklinn masklinn at masklinn.net
Wed Mar 16 22:48:19 CET 2011

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?)

More information about the Python-ideas mailing list