I've noticed that sometimes instance methods do not compare as identical (using is
rather than ==
), even when they relate to the same bound instance method e.g.
>>> class A(object):
... def f(self):
... print "hi"
...
>>> a = A()
>>> f1 = a.f
>>> f2 = a.f
>>> f1 is f2
False
>>> f1 == f2
True
I've ended up using ==
to check to see if two variables refer to the same bound method, but I was wondering if anyone knew why is
does not behave as I would expect?