11

In Python 2.7.9, when I assign a unbound method to a new attribute, and compare them by is statement, the result is False:

In [1]: class A(object):
   ...:     def a(self):
   ...:         pass
   ...:

In [2]: A._a = A.a

In [3]: print A.a, A._a
<unbound method A.a> <unbound method A.a>

In [4]: print id(A.a), id(A._a)
4499595904 4499595904

In [5]: A.a is A._a
Out[5]: False

This is very counter-intuitive and I could not find any reference or documentation to explain this behavior. What's more, when I test the same code in Python 3.4.2, the result turned to be True. I'm guessing that it's a bug in Python 2.7 but got fixed in Python 3, can anyone help me find the actual reason why this happen?

Reorx
  • 2,801
  • 2
  • 24
  • 29

0 Answers0