I considered 'default_factory' myself.... It seems good, but it
complicates the logic internally. For one thing, logically, we'd have to
also have 'missing_value_default' (unless we decree that missing values
have to be not-non-immutable, ah... immutable).
A further thought on where to put "filling in of defaults code" -- this
should probably be a separate routine in zope.schema:
setDefaults(instance)", which would set defaults (and validate? -- or
maybe call it "setDefaultsAndValidate").
PS anyone have idea or best practice on how to best through attributes,
avoiding shadowed ones? Seems like this is generally useful for
introspection of metadata.
From: Shane Hathaway [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 24, 2006 12:39 PM
To: Shaun Cutts
Subject: Re: [Zope3-dev] zope.schema: defaults for non-immutables...
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,
> want "a" to be a collection providing IFoo, which defaults to an empty
> collection. Each Bar implementing IBar should have its own instance of
I've run into this myself. How about:
a = Object(schema=IFoo, default_factory=Foo)
Zope3-dev mailing list