[ZODB-Dev] Re: false write conflicts

John Belmonte john at neggie.net
Tue Mar 2 11:15:42 EST 2004


Casey Duncan wrote:
> Augmented assignment causes a setattr on the containing object. This is
> the way Python works. These examples are semantically equivilant::
> 
>   self.x += 1
>   self.x = self.x + 1
>   setattr(self, 'x', self.x + 1)
> 
> They all cause self to be modified through __setattr__. If self is a
> persistent instance then it will be marked changed in all three cases
> above.

To be more accurate, it seems like

    foo.bar += 1

becomes the equivalent of

    x = foo.bar; x += 1; foo.bar = x

That is arguably a Python wart.  With regard to the containing object, 
it seems unfortunate to consider "foo.bar +=1" different than 
"foo.bar[a] = b".

This wrapper for Persistent.__setattr__ looks like it will suit my needs:

   class MyPersistent(Persistent):
     def __setattr__(self, key, val):
       if not (self.__dict__.has_key(key) and self.__dict__[key] is val):
         Persistent.__setattr__(self, key, val)


Thanks,
-John


-- 
http:// if  ile.org/



More information about the ZODB-Dev mailing list