[Python-Dev] Tuples and underorderable types
Raymond Hettinger
python at rcn.com
Fri Apr 24 19:52:50 CEST 2009
Does anyone have any ideas about what to do with issue 5830 and handling the problem in a general way (not just for sched)?
The basic problem is that decorate/compare/undecorate patterns no longer work when the primary sort keys are equal and the secondary
keys are unorderable (which is now the case for many callables).
>>> tasks = [(10, lambda: 0), (20, lambda: 1), (10, lambda: 2)]
>>> tasks.sort()
Traceback (most recent call last):
...
TypeError: unorderable types: function() < function()
Would it make sense to provide a default ordering whenever the types are the same?
def object.__lt__(self, other):
if type(self) == type(other):
return id(self) < id(other)
raise TypeError
Raymond
More information about the Python-Dev
mailing list