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

Alec Mitchell apm13 at columbia.edu
Fri May 28 14:15:14 EDT 2004


On Thursday 27 May 2004 02:17 pm, Alec Mitchell wrote:
> 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?
After a little more digging it turns out that this (a normal function) will 
get stored in the ZODB without errors (as my past experience would indicate).  
When I first tested it, I used a lambda function instead of a normal function 
definition out of laziness, and the lambda apparently won't pickle into the 
ZODB, though a normal function will.  So, fortunately, nothing seems to have 
changed between Python/Zope versions in this regard.  However, that still 
leaves the problem that doing this doesn't create a bound method, but a 
simple function, which cannot properly override the original method (because 
it lacks context).  Perhaps I should ask about this on the ZODB list?

Alec Mitchell



More information about the Zope mailing list