Re: Is (-1 ==True) True or False? Neither

2009-01-25 Thread Steven D'Aprano
On Sun, 25 Jan 2009 03:07:04 +0200, Oktay Şafak wrote: The reason is that when someone writes (-1 == True) he is clearly, definitely, absolutely asking for a boolean comparison, not a numerical one. If I wrote (-1 == True), and I'm not sure why I would, I would expect to get the answer

Is (-1 ==True) True or False? Neither

2009-01-24 Thread oktaysafak
Hi all, I ran into a strange case. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 ... >>> -1 == True False >>> -1 == False False This works though: >>> if -1: print "OK" OK After some head scratching, I realized that: - bool is a subclass of int and

Re: Is (-1 ==True) True or False? Neither

2009-01-24 Thread Robert Kern
On 2009-01-24 17:00, oktaysa...@superonline.com wrote: Hi all, I ran into a strange case. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 ... -1 == True False -1 == False False This works though: if -1: print OK OK After some head scratching, I

Re: Is (-1 ==True) True or False? Neither

2009-01-24 Thread Oktay Şafak
Robert Kern wrote: On 2009-01-24 17:00, oktaysa...@superonline.com wrote: Hi all, I ran into a strange case. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 ... -1 == True False -1 == False False This works though: if -1: print OK OK After some

Re: Is (-1 ==True) True or False? Neither

2009-01-24 Thread Terry Reedy
oktaysa...@superonline.com wrote: Hi all, I ran into a strange case. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 ... -1 == True False -1 == False False This works though: if -1: print OK OK After some head scratching, I realized that: -

Re: Is (-1 ==True) True or False? Neither

2009-01-24 Thread Robert Kern
On 2009-01-24 19:07, Oktay Şafak wrote: Robert Kern wrote: On 2009-01-24 17:00, oktaysa...@superonline.com wrote: Hi all, I ran into a strange case. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 ... -1 == True False -1 == False False This works

Re: Is (-1 ==True) True or False? Neither

2009-01-24 Thread Terry Reedy
Oktay Şafak wrote: That's what I'm trying to say: it would be more meaningful if int.__eq__ did a boolean comparison when the other operand is a boolean. For that to be done, int would have to know about its subclass, which generally is bad design. The reason is that when someone writes

Re: Is (-1 ==True) True or False? Neither

2009-01-24 Thread Oktay Şafak
I don't see how fixing this makes harder to treat True and False as first-class objects. If doing the right thing takes some special casing then be it, but I don't think it's so. True in ['something', False] In your semantics, this would evaluate to True because ('something' == True) is True.

Re: Is (-1 ==True) True or False? Neither

2009-01-24 Thread Oktay Şafak
Terry Reedy wrote: Oktay Şafak wrote: That's what I'm trying to say: it would be more meaningful if int.__eq__ did a boolean comparison when the other operand is a boolean. For that to be done, int would have to know about its subclass, which generally is bad design. Good point, but of