Raymond Hettinger wrote:
[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:
[Raymond Hettinger]
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.
[Michael Foord]
Is there something you don't like about this one:
http://code.activestate.com/recipes/576529/
Yes, that recipe has the basic idea!
It was originally written after you issued a challenge at PyCon UK last
year.
I think the implementation can be cleaned-up quite a bit
and it can be made as fast as hand-written code (not
the setup time, but the actual introduced method).
OK
I'll take it back to Christian and Menno and see what we can come up with.
Michael
Raymond
--
http://www.ironpythoninaction.com/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com