[Zope-dev] ZPatterns bug with patch

Steve Alexander steve@cat-box.net
Mon, 28 Aug 2000 23:28:05 +0100


"Phillip J. Eby" wrote:
> 
> At 10:22 AM 8/27/00 +0100, Steve Alexander wrote:
> >
> >I've fixed this by adding a test to the start of __set_attr__ of
> >DataSkins.py:
> >
> >    def __set_attr__(self,name,val,_v_dm_=_v_dm_):
> >+       if name=='id' and val==self.__dict__['id']:
> >+           return
> >        dm = self.__dict__[_v_dm_]
> 
> This looks reasonable, and backward-compatible, since __init__ guarantees
> the dict will have an id.  I'm not thrilled with adding more overhead to
> attribute setting, however, so I'll probably do it like this:
> 
> try:
>     dm = self.__dict__[_v_dm_]
> except KeyError:
>     if name=='id' and val==self.__dict__['id']: return
>     raise
> 
> Hopefully this should only perform the extra computations when the first
> part fails...

Are Python classes derived from DataSkin supposed to call
DataSkin.__init__ ?

Anyway, perhaps this would be a small improvement:

try:
    dm = self.__dict__[_v_dm_]
except KeyError:
    if (name=='id' and self.__dict__.has_key('id') 
        and val==self.__dict__['id']): return
    raise


--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net