isinstance(x, types.UnboundMethodType) feature

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.

Gareth Ladd <g.ladd@eris.qinetiq.com> writes:
Am I missing an subtelty of bound/unbound-ness?
Unbound and bound methods have the same type. Cheers, mwh (PS: inappropriate post for python-dev) -- I have long since given up dealing with people who hold idiotic opinions as if they had arrived at them through thinking about them. -- Erik Naggum, comp.lang.lisp

"Gareth Ladd" <g.ladd@eris.qinetiq.com> wrote in message news:400D2420.7040701@eris.qinetiq.com...
Am I missing an subtelty of bound/unbound-ness?
As of 2.2, C.hello.im_self == None while c.hello.im_self == c. Presume still same in 2.3. This is very much an implementation internal feature and not part of language definition. (Meaning: can be changed without notice.) I believe this is how repr() tells difference. This sort of question is better asked on comp.lang.python. It is about usage of current python rather than development of future python. Terry J. Reedy

"Terry Reedy" <tjreedy@udel.edu> writes:
"Gareth Ladd" <g.ladd@eris.qinetiq.com> wrote in message news:400D2420.7040701@eris.qinetiq.com...
Am I missing an subtelty of bound/unbound-ness?
As of 2.2, C.hello.im_self == None while c.hello.im_self == c.
Um, ITYM "As of 1.0.1" (which is the oldest version I could find when I went looking recently).
Presume still same in 2.3. This is very much an implementation internal feature and not part of language definition. (Meaning: can be changed without notice.)
Doesn't mean it is changed very often, though :-)
I believe this is how repr() tells difference.
It is. Cheers, mwh -- LINTILLA: You could take some evening classes. ARTHUR: What, here? LINTILLA: Yes, I've got a bottle of them. Little pink ones. -- The Hitch-Hikers Guide to the Galaxy, Episode 12
participants (3)
-
Gareth Ladd
-
Michael Hudson
-
Terry Reedy