[Zope3-dev] zope.schema: defaults for non-immutables... questions

Shane Hathaway shane at hathawaymix.org
Tue Jan 24 12:39:09 EST 2006


Shaun Cutts wrote:
> It would seem that the current default mechanism is poorly suited to 
> providing default values for non-immutables. For example:

"Mutable" is a better way to say "non-immutable". :-)

> class IBar( Interface ):
> 
>     a = Object( schema = IFoo, default = Foo() )
> 
> But if a “Foo” is not immutable this doesn’t make sense. (In my case, I 
> want “a” to be a collection providing IFoo, which defaults to an empty 
> collection. Each Bar implementing IBar should have its own instance of Foo.)

I've run into this myself.  How about:

a = Object(schema=IFoo, default_factory=Foo)

?

Shane


More information about the Zope3-dev mailing list