[Zope3-dev] Re: Field binding considered icky

Garrett Smith garrett at mojave-corp.com
Fri Apr 2 19:32:08 EST 2004


Maybe this is a silly question, but why not just pass the context to the
field validate method?

   field.validate(value, context)

Using adapters seems like a lot of infrastructure for something like
validation. I assume you see other advantages, beyond cleanup?

 --Garrett

"Jim Fulton" <jim at zope.com> wrote on 4/1/04 5:45 am:

Garrett Smith wrote:
> Jim Fulton wrote:
> 
>> I'm trying to catch up a bit on documentation.  I'm working on
>> README.txt files for zope.interface and zope.component and will be
>> updating the README.txt for zope.schema.
>>
>> There is a "feature" of schema fields that I really don't want to
>> document.   This feature is called "binding".  A field can be "bound"
>> to an object.  This creates a new field instance, which is a clone of
>> the original, that has a `context` attribute which is some object.
>> The object *may*, for example, be an object that has an attribute
that
>> is specified by the field.
> 
> 
> Apart from being hackish (er...icky?), why does the current approach 
> need to be revamped?

No other reason.  I think that this is an important reason though for
something that is *so* foundational.  The binding just feels very wrong.
I also want to merge zope.schema into zope.interface, so cleanliness is
even more important.  Finally, I think that fields are are a special
case
of attribute specifications. I think that interfaces need to provide a
uniform framework for defining interface attributes. Attribute
specifications need to fit in in a uniform way, so, for example, I want
the way fields get validated and the way methods get validated to be
similar.


> 
>>    We would get rid of the validate method of fields.
>>
>>    When we want to validate a field, we'll adapt it *with* it's
>>    context:
>>
>>      >>> validator = getMultiAdapter((field, context), IValidator)
>>      >>> validator.validate(value)
>>
>>    A disadvantage of this approach is that it will require either
>>    that:
>>
>>    - We remove validation logic from zope.schema, or
> 
> 
> This doesn't seem like a disadvantage.

I agree that this has a positive side too.

... Other comments snipped.

Thanks for the comments

Jim


-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org







More information about the Zope3-dev mailing list