[Python-Dev] Tuples and underorderable types

2009-04-24 Thread Raymond Hettinger
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

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Antoine Pitrou
Raymond Hettinger python at rcn.com writes: Would it make sense to provide a default ordering whenever the types are the same? This doesn't work when they are not the same :-) Instead, you could make the decorating a bit more sophisticated: decorated = [(key, id(value), value) for key,

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Raymond Hettinger
Would it make sense to provide a default ordering whenever the types are the same? This doesn't work when they are not the same :-) _ ~ @ @ \_/ Instead, you could make the decorating a bit more sophisticated: decorated = [(key, id(value), value) for key, value in blah(values)] or

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Scott Dial
Raymond Hettinger wrote: 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 No. This only makes it more

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Martin v. Löwis
I'm wondering if there is something we can do to mitigate the issue in a general way. It bites that the venerable technique of tuple sorting has lost some of its mojo. This may be an unintended consequence of eliminating default comparisons. I would discourage use of the

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Daniel Diniz
Raymond Hettinger wrote: The problem is that a basic python pattern is now broken in a way that may not readily surface during testing. I'm wondering if there is something we can do to mitigate the issue in a general way.  It bites that the venerable technique of tuple sorting has lost some

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Aahz
On Fri, Apr 24, 2009, Raymond Hettinger wrote: I'm wondering if there is something we can do to mitigate the issue in a general way. It bites that the venerable technique of tuple sorting has lost some of its mojo. This may be an unintended consequence of eliminating default comparisons.

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Terry Reedy
Raymond Hettinger wrote: 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

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Raymond Hettinger
I would discourage use of the decorate/sort/undecorate pattern, and encourage use of the key= argument. Or, if you really need to decorate into a tuple, still pass a key= argument. The bug report was actually about the sched module which used heapq to prioritize tuples consisting of times,

Re: [Python-Dev] Tuples and underorderable types

2009-04-24 Thread Terry Reedy
Raymond Hettinger wrote: I would discourage use of the decorate/sort/undecorate pattern, and encourage use of the key= argument. Or, if you really need to decorate into a tuple, still pass a key= argument. The bug report was actually about the sched module which used heapq to prioritize