[Python-ideas] Automatic comparisons by default

Doug Hellmann doug.hellmann at gmail.com
Wed Mar 16 22:40:45 CET 2011


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?

Doug




More information about the Python-ideas mailing list