[PEAK] very elementary peak.model question

Phillip J. Eby pje at telecommunity.com
Wed Jul 14 17:58:50 EDT 2004

At 04:35 PM 7/14/04 -0500, Doug Quale wrote:

>I tried LazyLoader with a model.Sequence feature and unless I'm doing
>something wrong it doesn't work.  (It works fine with model.Attribute.)
>This is a silly example, but it's short:
> >>> from peak.api import *
> >>> class bar(model.Element):
>         class x(model.Sequence):
>             pass
> >>> class lazy(storage.LazyLoader):
>         def load(self, ob, attr):
>             setattr(ob, attr, (1, 2))
> >>> b = bar()
> >>> b.x = lazy()

Don't use setattr in the lazy loader.  You *must* set directly into the 
object's dictionary, or call the slot's __set__ method if the attribute is 
stored in a slot rather than __dict__.

Also, don't use 'b.x =' to set the lazy loader into the object 
either.  Again, this should be via the dictionary.

Remember that lazy loaders and object state are part of the implementation 
of model elements, not a part of their interface.

(Frankly, I'm surprised you got it to work with model.Attribute; it's 
purely accidental that it happens to at the moment.)

Normally, the place where LazyLoaders are used is in a DM's '_load()' 
method, returned as part of a state dictionary that gets stuffed into the 

More information about the PEAK mailing list