[Zope] Override a method of an instance in the ZODB?

Alec Mitchell apm13 at columbia.edu
Thu May 27 17:17:32 EDT 2004


On Thursday 27 May 2004 02:00 pm, Passin, Tom wrote:
> In Python, you can override a method of an instance just by assigning it
> to another function, like this -
>
> class Test1:
>    def f1(self):
>       return "f1() of Test1"
>
> def f1():
>    return "f1() of instance"
>
> T1 = Test1()
> T1.f1 = f1
>
> Running this within the Python interpreter, try the following -
>
> >>> T1.f1()
>
> 'f1() of instance'
>
> Is this what you had in mind?

That's the idea, this is essentially what I did in my original post, except 
that your demo creates a function and not a bound method (e.g. it doesn't 
automatically make the instance the first argument).  I initially tried this, 
which failed because it wasn't really a method and had no way of obtaining 
its context.  

Then I learned how to convert a function into an instance method in python, 
which works great until the transaction commits to the ZODB.  Unfortunately, 
the ZODB won't store the method because it's 'unpicklable', the same is true 
for a plain function.  I vaguely recall being able to do this successfully in 
an earlier version of Zope (<=2.6.3, using python 2.1), though it was 
something of an accident and ended up causing a few problems (all of which 
were entirely my fault).  It seems strange that the ZODB would subsequently 
have lost this ability.

Thanks,
Alec Mitchell



More information about the Zope mailing list