[Zope3-dev] Interface field type

Jim Fulton jim at zope.com
Mon Nov 15 13:52:24 EST 2004


Shane Hathaway wrote:
> On Sun, November 14, 2004 12:34 pm, Jim Fulton said:
> 
>>Shane Hathaway wrote:
>>
>>>Today I wrote a containerViews directive and accidentally pointed the
>>>"for" attribute at a class rather than an interface.
>>
>>It should be legal to provide a class rather than an interface.
>>This should be reported as a bug.
> 
> 
> Oh.  The docstring describing the "for" attribute was pretty clear: "The
> containerViews will be for all objects that implement this interface." 
> It's a complete surprise to hear that this field should also accept a
> class.
> 
> Since I thought the docstring and many similar docstrings were telling the
> truth,

They are, but the truth is changing somewhat.

We decided a while ago that it should be possible to adapt classes
as well as interfaces.  (Of course, views are adapters.) I extended
the page directives to work with classes, but I haven't gotten to
adapter directives or to other directives, like containerViews
that deal with adapters.)

 > this weekend I changed directives that want an interface to use the
> new GlobalInterface type.  I wanted to be sure I (and other users new to
> Zope 3) didn't repeat the mistake of using a class where everyone else is
> using interfaces.
> 
> GlobalInterface is a simple subclass of GlobalObject.  It serves two
> purposes: it's a shortcut for GlobalObject(value_type=InterfaceField()),
> and it shows up in the API documentation, further clarifying which fields
> require interfaces.
> 
> 
>>Note again, however that a class should be allowed in this
>>case.
> 
> 
> Well, now I feel bad for adding excessive constraints.  I was certain I
> understood your intent, since the documentation was clear.
> 
> On the other hand, I don't feel good about reverting my changes, because
> the bug I found was quite painful to figure out.  I suggest we need to
> relax the GlobalInterface constraints one by one, adding tests that verify
> the code really works with classes in addition to interfaces.

Agreed.  I hope you didn't add this for page directives.

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