[Python-Dev] isinstance(x, types.UnboundMethodType) feature
Gareth Ladd
g.ladd at eris.qinetiq.com
Tue Jan 20 07:50:40 EST 2004
Hello all,
Whilst writing a routine to perform callbacks, I was performing a check
to ensure the callback method is callable and bound. After checking
"callable(x)" I then check that "x" is bound using "isinstance(x,
types.UnboundMethodType)". It appears the latter returns true if "x" is
a bound or an unbound class/instance method. Please have a look at the
following example. I would expect #3 to return "False".
<code>
import types
def hello():
print "hello"
class C:
def hello(self):
print "hello"
c=C()
print isinstance(hello, types.UnboundMethodType) #1
print isinstance(C.hello, types.UnboundMethodType) #2
print isinstance(c.hello, types.UnboundMethodType) #3
# Check it is actualy bound
f=c.hello
f() #4
</code>
<output>
False
True
True
hello
</output>
Am I missing an subtelty of bound/unbound-ness?
Thanks in advance,
Gareth.
More information about the Python-Dev
mailing list