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


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.)


A proposal to remedy: if the default is a callable object, it is assumed to be a factory.


How does this sound? (This would apply to missing_value as well.)


A few further questions:


1) who should be responsible for setting defaults, and how should it be done?

I have a base class from which I derive (e.g.) Bar, whose constructor loops through fields of interfaces provided by the instance:


        for iface in zope.interface.providedBy( self ):

            for fname, field in zope.schema.getFields( iface ).iteritems():


It checks default & missing_value, and sets them. However, if one field shadows another in the interfaces, there is no guarantee that I hit them in the right order. Might it not be good to have a “attributesProvidedBy( instance ) in zope.interface that guarantees that it passes back the most derived versions (and resolves consistently when there is no “most derived” )?


Also, currently, when something doesn’t have a definition, and is not required, I check first for “default” then for “missing_value”, and use the first I find as a missing value. Is this correct? How should “default” and “missing_value” interact with each other? What makes most sense to me is: (pseudocode):

If not specified:

    If default defined

        Use default


        If required

            Raise error


            If missing value defined

                Use missing value


                Raise error


Finally, a missing missing_value eventually gets “None” in the current Field constructor. Shouldn’t it be left undefined when it wasn’t specified? (Same for default.)


-        Shaun



Zope3-dev mailing list

Reply via email to