Re: Annoying behaviour of the != operator

2005-06-23 Thread Max
Jordan Rastrick wrote: I don't want to order the objects. I just want to be able to say if one is equal to the other. Here's the justification given: The == and != operators are not assumed to be each other's complement (e.g. IEEE 754 floating point numbers do not satisfy

Re: Annoying behaviour of the != operator

2005-06-23 Thread Steven D'Aprano
Max wrote: Jordan Rastrick wrote: Well, never, ever use equality or inequality operations with floating point numbers anyway, in any language, as they are notoriously unreliable due to the inherent inaccuracy of floating point. Thats another pitfall, I'll grant, but its a pretty well known

Re: Annoying behaviour of the != operator

2005-06-13 Thread Rocco Moretti
Before I answer, let me clarify my position. I am NOT advocating any change for the 2.x series. I'm not even forwarding any particular proposal for 3.0/3000. My key (and close to sole) point is that behavior ofis conceptually distinct from ordering in a sorted list, even though the

Re: Annoying behaviour of the != operator

2005-06-12 Thread pmaupin
If a behavior change is possible at all, I think a more reasonable behavior would be: if any rich comparison methods are defined, always use rich comparisons (and throw an exception if the required rich comparison method is not available). This would at least have the benefit of letting users

Re: Annoying behaviour of the != operator

2005-06-10 Thread greg
David M. Cooke wrote: To solve that, I would suggest a fourth category of arbitrary ordering, but that's probably Py3k material. We've got that: use hash(). [1+2j, 3+4j].sort(key=hash) What about objects that are not hashable? The purpose of arbitrary ordering would be to provide an

Re: Annoying behaviour of the != operator

2005-06-10 Thread Robert Kern
greg wrote: David M. Cooke wrote: To solve that, I would suggest a fourth category of arbitrary ordering, but that's probably Py3k material. We've got that: use hash(). [1+2j, 3+4j].sort(key=hash) What about objects that are not hashable? The purpose of arbitrary ordering would be to

Re: Annoying behaviour of the != operator

2005-06-10 Thread Steven D'Aprano
On Thu, 09 Jun 2005 08:10:09 -0400, Dan Sommers wrote: The main problem is that Python is trying to stick at least three different concepts onto the same set of operators: equivalence (are these two objects the same?), ordering (in a sorted list, which comes first?), and mathematical size.

Re: Annoying behaviour of the != operator

2005-06-10 Thread Rocco Moretti
Dan Sommers wrote: On Thu, 09 Jun 2005 15:50:42 +1200, Greg Ewing [EMAIL PROTECTED] wrote: Rocco Moretti wrote: The main problem is that Python is trying to stick at least three different concepts onto the same set of operators: equivalence (are these two objects the same?), ordering (in a

Re: Annoying behaviour of the != operator

2005-06-10 Thread Dan Bishop
Steven D'Aprano wrote: ... If you were to ask, which is bigger, 1+2j or 3+4j? then you are asking a question about mathematical size. There is no unique answer (although taking the absolute value must surely come close) and the expression 1+2j 3+4j is undefined. But if you ask which should

Re: Annoying behaviour of the != operator

2005-06-10 Thread Jp Calderone
On 10 Jun 2005 09:05:53 -0700, Dan Bishop [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: ... If you were to ask, which is bigger, 1+2j or 3+4j? then you are asking a question about mathematical size. There is no unique answer (although taking the absolute value must surely come close) and the

Re: Annoying behaviour of the != operator

2005-06-10 Thread Terry Reedy
Rocco Moretti [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The wackyness I refered to wasn't that a list of complex numbers isn't sortable, but the inconsistent behaviour of list sorting. As you mentioned, an arbitraty collection of objects in a list is sortable, but as soon as

Re: Annoying behaviour of the != operator

2005-06-10 Thread Rocco Moretti
George Sakkis wrote: Rocco Moretti wrote: One way to handle that is to refuse to sort anything that doesn't have a natural order. But as I understand it, Guido decided that being able to sort arbitrary lists is a feature, not a bug. He has changed his mind since then

Re: Annoying behaviour of the != operator

2005-06-10 Thread David M. Cooke
Robert Kern [EMAIL PROTECTED] writes: greg wrote: David M. Cooke wrote: To solve that, I would suggest a fourth category of arbitrary ordering, but that's probably Py3k material. We've got that: use hash(). [1+2j, 3+4j].sort(key=hash) What about objects that are not hashable? The purpose of

Re: Annoying behaviour of the != operator

2005-06-09 Thread Antoon Pardon
Op 2005-06-08, Mahesh schreef [EMAIL PROTECTED]: No, why should Python assume that if you use != without supplying a __ne__ that this is what you want? Without direction it will compare the two objects which is the default behavior. So, s != t is True because the ids of the two objects are

Re: Annoying behaviour of the != operator

2005-06-09 Thread Dan Sommers
On Thu, 09 Jun 2005 15:50:42 +1200, Greg Ewing [EMAIL PROTECTED] wrote: Rocco Moretti wrote: The main problem is that Python is trying to stick at least three different concepts onto the same set of operators: equivalence (are these two objects the same?), ordering (in a sorted list, which

Re: Annoying behaviour of the != operator

2005-06-09 Thread David M. Cooke
Greg Ewing [EMAIL PROTECTED] writes: Rocco Moretti wrote: This gives the wacky world where [(1,2), (3,4)].sort() works, whereas [1+2j, 3+4j].sort() doesn't. To solve that, I would suggest a fourth category of arbitrary ordering, but that's probably Py3k material. We've got that: use

Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
Can anybody please give me a decent justification for this: class A(object): def __init__(self, a): self.a = a def __eq__(self, other): return self.a == other.a s = A(3) t = A(3) print s == t True print s != t True I just spent a long, long time tracking down a bug

Re: Annoying behaviour of the != operator

2005-06-08 Thread Dave Benjamin
Jordan Rastrick wrote: Surely the != operator should, if no __ne__ method is present for either object, check to see if an __eq__ method is defined, and if so, return its negation? Actually, that brings me to a wider question - why does __ne__ exist at all? Surely its completely

Re: Annoying behaviour of the != operator

2005-06-08 Thread Fredrik Lundh
Jordan Rastrick wrote: I just spent a long, long time tracking down a bug in a program that results from this behaviour. Surely the != operator should, if no __ne__ method is present for either object, check to see if an __eq__ method is defined, and if so, return its negation? Actually,

Re: Annoying behaviour of the != operator

2005-06-08 Thread Mahesh
No, why should Python assume that if you use != without supplying a __ne__ that this is what you want? Without direction it will compare the two objects which is the default behavior. So, s != t is True because the ids of the two objects are different. The same applies to, for example s t and s

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
Just because a behaviour is documented, doesn't mean its not counter intutitive, potentially confusing, and unnessecary. I have spent a fair amount of time reading the Python docs. I have not yet memorised them. I may have read this particular section of the reference manual, or I may have not, I

Re: Annoying behaviour of the != operator

2005-06-08 Thread Rocco Moretti
Jordan Rastrick wrote: Unless someone can explain some sort of problem that arises from having != take advantage of a __eq__ method where present, I'd suggest that it should do so in Python 2.5. If you're serious about this proposal, please formalize it in a PEP. Things to specify: How

Re: Annoying behaviour of the != operator

2005-06-08 Thread John Roth
Jordan Rastrick [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Well, I don't really want the objects to be comparable. In fact, to quote that PEP you linked: An additional motivation is that frequently, types don't have a natural ordering, but still need to be compared

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
I'd suggest the only nessecary change is, if objects a,b both define __eq__ and not __ne__, then a != b should return not (a == b) If a class defines __ne__ but not __eq__, well that seems pretty perverse to me. I don't especially care one way or another how thats resolved to be honest. The

Re: Annoying behaviour of the != operator

2005-06-08 Thread Matt Warden
Jordan, On 8 Jun 2005 11:44:43 -0700, Jordan Rastrick [EMAIL PROTECTED] wrote: But I explicitly provided a method to test equality. And look at the plain english meaning of the term Not equals I think its pretty reasonable Indeed. Furthermore, it seems quite silly that these would be

Re: Annoying behaviour of the != operator

2005-06-08 Thread Robert Kern
Jordan Rastrick wrote: Are there any other reasonable examples people can give where it makes sense for != and == not to be each other's complement? __eq__ and __ne__ implement *rich* comparisons. They don't have to return only True or False. In [1]:import Numeric In [2]:a =

Re: Annoying behaviour of the != operator

2005-06-08 Thread George Sakkis
Jordan Rastrick wrote: I'd suggest the only nessecary change is, if objects a,b both define __eq__ and not __ne__, then a != b should return not (a == b) If a class defines __ne__ but not __eq__, well that seems pretty perverse to me. I don't especially care one way or another how thats

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
Well, I'll admit I haven't ever used the Numeric module, but since PEP207 was submitted and accepted, with Numeric as apparently one of its main motivations, I'm going to assume that the pros and cons for having == and ilk return things other than True or False have already been discussed at

Re: Annoying behaviour of the != operator

2005-06-08 Thread Kay Schluehr
Jordan Rastrick wrote: Just because a behaviour is documented, doesn't mean its not counter intutitive, potentially confusing, and unnessecary. I have spent a fair amount of time reading the Python docs. I have not yet memorised them. I may have read this particular section of the

Re: Annoying behaviour of the != operator

2005-06-08 Thread Rocco Moretti
Matt Warden wrote: Jordan, On 8 Jun 2005 11:44:43 -0700, Jordan Rastrick [EMAIL PROTECTED] wrote: But I explicitly provided a method to test equality. And look at the plain english meaning of the term Not equals I think its pretty reasonable Indeed. Furthermore, it seems quite silly

Re: Annoying behaviour of the != operator

2005-06-08 Thread Christopher Subich
Peter Hansen wrote: I can see only one comment that seems to describe that situation, where it refers to IEEE 754 floating point numbers do not satisfy [== being the complement of !=]. (Though that may be justification enough for the feature...) To my naive eye, that possibility seems

Re: Annoying behaviour of the != operator

2005-06-08 Thread Jordan Rastrick
I'm a Maths and Philosophy undergraduate first and foremost, with Computer Science as a tacked on third; I've studied a fair bit of logic both informally and formally, and am familiar with things such as the non-nessecity of the law of the excluded middle in an arbitrary propositional calculus

Re: Annoying behaviour of the != operator

2005-06-08 Thread Mahesh
I understand that what makes perfect sense to me might not make perfect sense to you but it seems a sane default. When you compare two objects, what is that comparision based on? In the explicit is better than implicit world, Python can only assume that you *really* do want to compare objects

Re: Annoying behaviour of the != operator

2005-06-08 Thread John Roth
Jordan Rastrick [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Well, I'll admit I haven't ever used the Numeric module, but since PEP207 was submitted and accepted, with Numeric as apparently one of its main motivations, I'm going to assume that the pros and cons for having == and

Re: Annoying behaviour of the != operator

2005-06-08 Thread Dan Bishop
Mahesh wrote: I understand that what makes perfect sense to me might not make perfect sense to you but it seems a sane default. When you compare two objects, what is that comparision based on? In the explicit is better than implicit world, Python can only assume that you *really* do want to

Re: Annoying behaviour of the != operator

2005-06-08 Thread Peter Hansen
Christopher Subich wrote: Perhaps the language should offer the sensible default of (!=) == (not ==) if one of them but not the other is overriden, but still allow overriding of both. I believe that's exactly what Jordan is promoting and, having been bitten in exactly the same way I would

Re: Annoying behaviour of the != operator

2005-06-08 Thread Peter Hansen
Robert Kern wrote: The problem arises that, in the presence of rich comparisons, (a == b) is not always a boolean value, while (a is b) is always a boolean value. But that still doesn't mean that in a case where a == b (via __eq__) returns a non-boolean, __ne__ would not be defined as well.

Re: Annoying behaviour of the != operator

2005-06-08 Thread Greg Ewing
Jordan Rastrick wrote: But I explicitly provided a method to test equality. Actually, no, you didn't. You provided a method to define the meaning of the operator spelled '==' when applied to your object. That's the level of abstraction at which Python's __xxx__ methods work. They don't make any

Re: Annoying behaviour of the != operator

2005-06-08 Thread Greg Ewing
Jordan Rastrick wrote: Where are the 'number of situations' where __ne__ cannot be derived from __eq__? Is it just the floating point one? I must admit, I've missed any others. The floating point one is just an example, it's not meant to be the entire justification. Some others: * Numeric

Re: Annoying behaviour of the != operator

2005-06-08 Thread Greg Ewing
Rocco Moretti wrote: The main problem is that Python is trying to stick at least three different concepts onto the same set of operators: equivalence (are these two objects the same?), ordering (in a sorted list, which comes first?), and mathematical size. A possible compromise would be