types.UnboundMethodType is types.MethodType

Carlos Ribeiro carribeiro at gmail.com
Thu Oct 7 03:54:36 CEST 2004

Just curious. I was trying to test for a class method in some code of
mine, and stumbled on a few things that I really could not understand:

# C is a class, m is a class method
>>> c.m
<bound method C.m of <__main__.C instance at 0x0120E350>>
>>> isinstance(c.m, types.UnboundMethodType)
# C is a class, cm is a class method
>>> C.cm
<bound method classobj.cm of <class __main__.C at 0x0120D870>>
>>> isinstance(C.cx, types.UnboundMethodType)
>>> types.UnboundMethodType is types.MethodType
>>> types.UnboundMethodType, types.MethodType
(<type 'instancemethod'>, <type 'instancemethod'>)
>>> id(types.UnboundMethodType), id(types.MethodType)
(504034256, 504034256)

I don't get it. Why to have two different identifiers that are in fact the same?

BTW - That's my Python version:
>>> sys.version
'2.3.2 (#49, Nov 13 2003, 10:34:54) [MSC v.1200 32 bit (Intel)]'
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com

More information about the Python-list mailing list