[pypy-dev] Unbound method must be called with instance as first argument

holger krekel hpk at trillke.net
Mon Jul 5 12:15:24 CEST 2004

Hey Richard, 

[Richard Emslie Sat, Jul 03, 2004 at 05:54:23PM +0100]
> Seems the problem is that Method does not have a __get__ (since C.m 
> returns a Method not a Function via __get__ while assigning to D).  In 
> other words
> mm = C.m
> D.m = mm
> assert D.m == mm     # True since no __get__()
> assert C.m != mm     # True since __get__() creates a new method
> Some simple fixes are
> 1. add a __get__() method to interpreter.function.Method which forwards 
> request onto w_function attribute.

yes, i think this is the right way. 

> 2. put a hack in objspace/descrooperation.DescrOperation in get() to 
> handle special case for Method (yuk!)

yuk indeed! 

> The CPython implementation seems to be doing some hairy caching instead of 
> creating new method each __get__(), so it hard to tell if this is correct 
> behaviour.  And the above fixes are only based on my understanding of 
> desciptors, which has a high probability to be wrong.  If someone backs me 
> up I can commit fix 1. :-)

I might have a lower probabiliy of beeing wrong but Samuele probably has one
close to zero.  I suggest you go with your first solution (and also write 
some tests for it :-).  

Btw, it would be really nice to be able to run app-level tests against
CPython apart from PyPy/std basically ensuring us we are beeing compatible.  
However, this probably can only be implemented nicely after we do the utest-switch. 



More information about the Pypy-dev mailing list