[Python-Dev] Deprecated __cmp__ and total ordering
Raymond Hettinger
python at rcn.com
Tue Mar 10 14:53:26 CET 2009
[Mart Sõmermaa]
> To provide total ordering without __cmp__ one has to implement all of
> __lt__, __gt__, __le__, __ge__, __eq__ and __ne__. However, in all
> but a few cases it suffices only to provide a "real" implementation for
> e.g. __lt__ and define all the other methods in terms of it as follows:
FWIW, I'm working on a solution for the problem using class decorators.
The idea is that it would scan a class and fill-in missing methods based
on the ones already there. That way, any one of the four ordering
relations can be provided as a starting point and we won't have to
annoint one like __lt__ as the one true underlying method.
When it's ready, I'll bring it to python-dev for discussion.
Raymond
More information about the Python-Dev
mailing list