For object and function references, id
and is
behave as I would have expected, but for methods, they don't. The example provided is for a builtin method, but I see the same for other methods.
>>> fred = "abcd"
>>> bill = fred
>>> id(fred)
139890760324016
>>> id(bill)
139890760324016
>>> bill is fred
True
>>> harry = fred.join
>>> id(fred.join)
139890761574896
>>> id(harry)
139890760308992
>>> harry is fred.join
False
>>> fred.join
<built-in method join of str object at 0x7f3adb1393b0>
>>> harry
<built-in method join of str object at 0x7f3adb1393b0>
>>> harry == fred.join
True
>>>
>>> def testFn():
... return
...
>>> mary = testFn
>>> id(testFn)
139890760327952
>>> id(mary)
139890760327952
>>> mary is testFn
True
This behavior seems to make my life more difficult, which is not something I'm used to from python. Is there a simple way to do a test for the same reference that includes methods or will I need to make methods a special case, using ==
for methods and is
for other objects?