A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-January/042110.html below:

[Python-Dev] isinstance(x, types.UnboundMethodType) feature

[Python-Dev] isinstance(x, types.UnboundMethodType) featureGareth 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4