Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Greg Ewing
Daniel Stutzbach wrote: > I apologize if this is a silly question, but what would be the > difference between the proposed __richcmp__ and the old __cmp__ that's > being removed? __richcmp__ would have the same signature as the C-level tp_richcmp slot, i.e. taking a code indicating which comparis

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Terry Reedy
Terry Reedy schrieb: | > In any case, this point is that dict ordering is as arbitrary as ordering, | > for instance, a dict and a string. Since Guido stopped the experiment of | > totally ordering all objects when complex nums were added, consistency | > suggests that all fake orderings be el

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Daniel Stutzbach
On 3/21/07, Greg Ewing <[EMAIL PROTECTED]> wrote: > In addition to this, what about the idea of a Python-level > __richcmp__ method? It would provide a single point of override > for classes that wanted to use it, and it shouldn't upset any > default behaviours since it's just exposing what's there

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Greg Ewing
Adam Olsen wrote: > On 3/20/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > > > I've used a __key__() method quite successfully in my own code. Maybe > > we should provide a mixin like:: > > This seems to match what I've usually needed, but I'm not sure it's > worth putting in python proper. In

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Guido van Rossum
On 3/21/07, Georg Brandl <[EMAIL PROTECTED]> wrote: > Terry Reedy schrieb: > > "Georg Brandl" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > | Yes, but dictionaries had an explicit ordering in dict_compare() which > > was > > | deleted. > > > > Is dict_compare something added i

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Georg Brandl
Terry Reedy schrieb: > "Georg Brandl" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | Yes, but dictionaries had an explicit ordering in dict_compare() which > was > | deleted. > > Is dict_compare something added in 2.5? It is neither a builtin or dict > method in 2.4. No, it

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Collin Winter
On 3/21/07, Thomas Wouters <[EMAIL PROTECTED]> wrote: > On 3/21/07, Collin Winter <[EMAIL PROTECTED]> wrote: > > On 3/20/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > [snip] > > > Or we could just have 2.6 warn about the presence (or use) of __cmp__ > > > -- users can write equivalent code us

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Thomas Wouters
On 3/21/07, Collin Winter <[EMAIL PROTECTED]> wrote: On 3/20/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: [snip] > Or we could just have 2.6 warn about the presence (or use) of __cmp__ > -- users can write equivalent code using __lt__ etc. themselves and > probably do a better job. Fair enou

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Steven Bethard
On 3/21/07, Adam Olsen <[EMAIL PROTECTED]> wrote: > On 3/20/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > > I've used a __key__() method quite successfully in my own code. Maybe > > we should provide a mixin like:: > > > > class KeyedComparisonMixin(object): > > def __eq__(self, othe

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Adam Olsen
On 3/21/07, Collin Winter <[EMAIL PROTECTED]> wrote: > On 3/20/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > [snip] > > Or we could just have 2.6 warn about the presence (or use) of __cmp__ > > -- users can write equivalent code using __lt__ etc. themselves and > > probably do a better job. > >

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Adam Olsen
On 3/20/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > On 3/20/07, Collin Winter <[EMAIL PROTECTED]> wrote: > > Quoting from the commit message for r51533, which removed the default > > ordering: > > > > """ > > A general problem with getting lots of these tests to pass is > > the reality that fo

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Collin Winter
On 3/20/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: [snip] > Or we could just have 2.6 warn about the presence (or use) of __cmp__ > -- users can write equivalent code using __lt__ etc. themselves and > probably do a better job. Fair enough. Is anyone collecting a list of these --py3k warning

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Terry Reedy
"Georg Brandl" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Yes, but dictionaries had an explicit ordering in dict_compare() which was | deleted. Is dict_compare something added in 2.5? It is neither a builtin or dict method in 2.4. In any case, this point is that dict order

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Guido van Rossum
On 3/21/07, Georg Brandl <[EMAIL PROTECTED]> wrote: > BTW, was it intentional that dicts can't be compared via ">" and "<" > anymore? Yes. In old Python it made sense since all objects were supposed to be orderable *somehow* (in the truly distant past, comparisons weren't even allowed to raise exc

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Georg Brandl
Josiah Carlson schrieb: > Georg Brandl <[EMAIL PROTECTED]> wrote: >> Guido van Rossum schrieb: >> > I haven't taken any action, and it looks like __cmp__ isn't being >> > called. I'd rather not add it back; if you want it back, could you at >> > least write up a brief PEP? A patch would also help;

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Josiah Carlson
Georg Brandl <[EMAIL PROTECTED]> wrote: > Guido van Rossum schrieb: > > I haven't taken any action, and it looks like __cmp__ isn't being > > called. I'd rather not add it back; if you want it back, could you at > > least write up a brief PEP? A patch would also help; I recall that it > > was quit

Re: [Python-3000] Total ordering and __cmp__

2007-03-21 Thread Georg Brandl
Guido van Rossum schrieb: > I haven't taken any action, and it looks like __cmp__ isn't being > called. I'd rather not add it back; if you want it back, could you at > least write up a brief PEP? A patch would also help; I recall that it > was quite a relief being able to cut it out, so I expect th

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Terry Reedy
"Guido van Rossum" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | But can this work? It might end up calling cmp() on two incomparable | objects. For __lt__ etc. that might be the right answer, but for | __eq__ it is *not* -- the default __eq__ and __ne__ *must* compare | object id

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Steven Bethard
On 3/20/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > I've used a __key__() method quite successfully in my own code. Maybe > we should provide a mixin like:: > > class KeyedComparisonMixin(object): > def __eq__(self, other): > return self.__key__() == other.__key__() [sn

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Guido van Rossum
On 3/20/07, Collin Winter <[EMAIL PROTECTED]> wrote: > On 3/20/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > I haven't taken any action, and it looks like __cmp__ isn't being > > called. I'd rather not add it back; if you want it back, could you at > > least write up a brief PEP? A patch woul

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Collin Winter
On 3/20/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > I haven't taken any action, and it looks like __cmp__ isn't being > called. I'd rather not add it back; if you want it back, could you at > least write up a brief PEP? A patch would also help; I recall that it > was quite a relief being able

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Guido van Rossum
How would that produce the desired behavior that == and != are defined on all objects, but <, <=, >= and > are not? We're quickly approaching python-ideas land... :) On 3/20/07, Steven Bethard <[EMAIL PROTECTED]> wrote: > On 3/20/07, Collin Winter <[EMAIL PROTECTED]> wrote: > > Quoting from the co

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Steven Bethard
On 3/20/07, Collin Winter <[EMAIL PROTECTED]> wrote: > Quoting from the commit message for r51533, which removed the default > ordering: > > """ > A general problem with getting lots of these tests to pass is > the reality that for object types that have a natural total ordering, > implementing __

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Guido van Rossum
But can this work? It might end up calling cmp() on two incomparable objects. For __lt__ etc. that might be the right answer, but for __eq__ it is *not* -- the default __eq__ and __ne__ *must* compare object identity. (What is this __cmp you refer to? A typo for __cmp__ or for cmp?) --Guido On 3

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Terry Reedy
"Collin Winter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Quoting from the commit message for r51533, which removed the default ordering: | | What's the status on this? FWIW, I would like to see __cmp__ stay as a | fallback measure if __eq__, __ne__, __lt__, etc aren't define

Re: [Python-3000] Total ordering and __cmp__

2007-03-20 Thread Guido van Rossum
I haven't taken any action, and it looks like __cmp__ isn't being called. I'd rather not add it back; if you want it back, could you at least write up a brief PEP? A patch would also help; I recall that it was quite a relief being able to cut it out, so I expect that patching it back in would be qu