UnboundMethodType and MethodType

Schüle Daniel uval at rz.uni-karlsruhe.de
Wed Feb 8 12:55:47 EST 2006


[...]

>> It's the same function, whether it's bound or not. Thus, it should 
>> always have the same type. 
> 
> 
> No, it's not the same function. You got the same id because you didn't 
> bind B.bar and b.bar to anything so the id was reused.

thank you for the explanation
it's indeed tricky with reusing the id
are there some pages on the net to read more about it?

 >>> class Q:
...     def __init__(self,val):
...             self.val = val
...     def bar(self):
...             print self.val
...
 >>> x = Q.bar
 >>> y = Q("test").bar
 >>> x
<unbound method Q.bar>
 >>> y
<bound method Q.bar of <__main__.Q instance at 0x40427a6c>>
 >>> y()
test
 >>> id(x)
1078081812
 >>> id(y)
1078082492
 >>>

the same id-value would enforce two objects to be
of the same type (trivial case)
the reverse is not necessarily true
in this case x.bar and y.bar are of the same type

UnboundMethodType is still not very suitable name for Q().bar
:-/

Regards, Daniel




More information about the Python-list mailing list