[Zope3-dev] Interface field type

Shane Hathaway shane at hathawaymix.org
Mon Nov 15 13:44:27 EST 2004


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

Shane




More information about the Zope3-dev mailing list