[Python-ideas] Automatic comparisons by default
Facundo Batista
facundobatista at gmail.com
Tue Mar 15 19:03:21 CET 2011
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.
Some considerations:
- You can give decorators that fill the spaces, but I think that would
be less error prone, more clean and less surprising with those rules
(specially the first one).
- If somebody wants for != not to be the opposite of ==, both methods
can be defined. The same for __le__ and __ge__.
- All that would be needed for comparisons (for those normal objects
where those rules apply) would be __le__ and __eq__, which is what you
need to replace __cmp__.
- *I* don't know if this behaviour will break something (couldn't find a case).
What do you think?
Regards,
--
. Facundo
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
More information about the Python-ideas
mailing list