[issue1617161] Instance methods compare equal when their self's are equal

Frank Niessink report at bugs.python.org
Sun Mar 9 14:13:50 CET 2008


Frank Niessink <frank at niessink.com> added the comment:

Just to reiterate the original bug report: the issue (for me) is that
currently (python 2.5):
>>> [].__add__  == [].__add__
True
>>> [].__add__  == [1].__add__
False

Or, using a non-builtin class:
>>> class C(object):
...   def __eq__(self, other):
...     return False
...   def foo(self):
...      pass
...
>>> C().foo == C().foo
False
>>> class C(object):
...   def __eq__(self, other):
...     return True
...   def foo(self):
...     pass
...
>>> C().foo == C().foo
True

I think it makes little sense that the equality test for the instance
methods takes the equality of the instances into account. Imho, this
behaviour is inconsistent with the principle of no surprises. The
correct behaviour (again imho of course) is that instance methods only
compare equal to the same instance method of the same instance, where 
'same instance' is based on 'is' not on '=='.  

Cheers, Frank

_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1617161>
_____________________________________


More information about the Python-bugs-list mailing list