[Python-ideas] Automatic comparisons by default
Raymond Hettinger
raymond.hettinger at gmail.com
Tue Mar 15 20:18:07 CET 2011
On Mar 15, 2011, at 11:03 AM, Facundo Batista wrote:
> Two very related proposals:
>
> 1. On "!=", if Python doesn't find __ne__, use "not __eq__()".
>
> 2. On "<=", if Python doesn't find __le__, use "__eq__() or __lt__()".
> The same for ">=", of course.
It's a little more complicated than "if Python doesn't find ...".
In Python 3, object() already has __le,__, __gt__, __ge__, and __gt__,
so those methods always get found.
You can use an identity check to see if those methods have been
overridden, but I think the only truly correct way to tell if one of the
rich comparison methods is defined is to call it and see whether
it returns NotImplemented.
Raymond
More information about the Python-ideas
mailing list