[Zope-dev] __getattr__ revisited

Dieter Maurer dieter@handshake.de
Wed, 16 Apr 2003 21:37:45 +0200


Johan Carlsson [EasyPublisher] wrote at 2003-4-16 14:12 +0000:
 > I just read an old thread about overriding __getattr__ without
 > breaking acquisition.
 > Using Implicit.inheritedAttributes('__getattr__') didn't work, and I'm not
 > sure if using Implicit.__class__.__getattr__ even gives me the correct 
 > __getattr__?

Jim (Fulton) has removed the need to call the inherited "__getattr__"
from "Persistent".

 > Anyway I found a way around this using __dict__ explicitly.

This is to avoid acquisition which is likely to cause ininite
recursion (silently broken by the "RuntimeError: too many recursion"
(or so).

 > In the __of__ wrapper I save the parent:
 > self.__dict__['_v_parent']=parent
 > 
 > and in the end of __getattr__ I put
 > 
 > if self.__dict__.has_key('_v_parent'):
 >    return getattr(self.__dict__['_v_parent'], name)
 > 
 > It seams to work, but I just want to check for any problems with this approach.

Are you sure, you need "__getattr__"?

  Acquisition would automatically look for "name" in "parent" when
  "self" does not have this attribute.


Dieter