Issue1627

classification
Title: foo == None calls foo.equals(null)
Type: behaviour Severity: normal
Components: Core Versions: 2.5.0
Milestone:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: doublep, rjolivet, zyasoft
Priority: Keywords:

Created on 2010-07-05.15:13:06 by rjolivet, last changed 2010-08-06.05:40:38 by zyasoft.

Messages
msg5872 (view) Author: Raphael Jolivet (rjolivet) Date: 2010-07-05.15:13:04
Hello,

I am working on a Jython script that calls a library of mine.
I have had a bug recently because a script test "foo ==  None" happened to call "foo.equals(null)".

The custom "equals" method I had written was not expecting to be tested against null values and then crashed.

I believe that Jython could avoid this. A test 'foo == None' could just be translated to the Java counterpart 'foo == null'. I do not believe that "equals" is supposed to expect a call with null values.

What do you think ?
Thanks,

Raphael
msg5873 (view) Author: (doublep) Date: 2010-07-06.09:53:08
Not a bug.  CPython:

>>> class Foo (object):
...   def __eq__(self, that):
...     return True
...
>>> Foo () == None
True

You should use 'foo is None' instead.
msg5942 (view) Author: Jim Baker (zyasoft) Date: 2010-08-06.05:40:37
Current behavior seems reasonable enough to me. From http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#equals(java.lang.Object) :

"For any non-null reference value x, x.equals(null) should return false."

Given that the Java value of Jython's None is defined to be null, this is the correct behavior. Also, as doublep points out in msg5873, you normally want to use 'is None', this will be less surprising.
History
Date User Action Args
2010-08-06 05:40:38zyasoftsetstatus: open -> closed
resolution: wont fix
messages: + msg5942
nosy: + zyasoft
2010-07-06 09:53:09doublepsetnosy: + doublep
messages: + msg5873
2010-07-05 15:13:06rjolivetcreate