Alex Martelli aleaxit at
Sat May 12 11:47:33 EDT 2001

"Michael Hudson" <mwh at> wrote in message
news:m3d79eraqw.fsf at
> James_Althoff at writes:
> > Does anyone know what the "class" argument -- arg 3 -- to
> > new.instancemethod is for?
> It doesn't seem to serve any "real" purpose other than documentation.

*blink*... come again...?

>>> import new
>>> class A: pass
>>> class B: pass
>>> def f(*args): print 'f',args
>>> fa=new.instancemethod(f,None,A)
>>> fb=new.instancemethod(f,None,B)
>>> a=A()
>>> fa(a)
f (<__main__.A instance at 007B1E2C>,)
>>> fb(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unbound method must be called with class instance 1st argument

That doesn't seem a case of "no real purpose other than documentation"
to me... when I use new.instancemethod to generate an unbound method,
I _do_ have to tell it what class it is a method of, and far from being just
a tidbit for documentation it will be checked at runtime, raising TypeError
if used inappropriately.


More information about the Python-list mailing list