Annoying behaviour of the != operator

Robert Kern rkern at ucsd.edu
Wed Jun 8 17:19:18 EDT 2005


Jordan Rastrick wrote:

> Mahesh raised the argument some posts back that Python should not 'just
> guess' what you want. But the problem is, it *already does* - it
> guesses you want object identity comparison if you haven't written
> __ne__. But if __ne__ is not provided, than the negation of
> 
> a==b
> 
> is *surely* a better guess for a != b than the negation of
> 
> a is b

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. 
I *would* prefer that (a != b) raise an error when __ne__ isn't 
provided, but such is life until 3.0.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list