[Zope3-dev] Re: Usage of IAnnotations disrespects interface declaration

Philipp von Weitershausen philipp at weitershausen.de
Sun Dec 10 18:46:54 EST 2006


Christian Theune wrote:
> Issue 735 (http://www.zope.org/Collectors/Zope3-dev/735) describes a
> problem how IAnnotations are used within Zope.
> 
> I agree that this should be changed. I'd like to get some discussion on
> the mailinglist on how to change this (I've added a short analysis in
> the transcript of the issue).

In the issue you write:

> I can see two ways:
> 
> 1. Extend the IAnnotations interface to grow the necessary
>   methods and support the existing use cases
> 
> 2. Remove the ability from the existing attribute annotation
>   and re-write the code that uses it to avoid using __iter__
>   __contains__ and items.

Both are not acceptable, especially option #1. We can't just change 
existing contracts as we see fit.

Here's what I suggest: We create a new interface based on IAnnotations 
that expresses __iter__ and __contains__::

   class IIterableAnnotations(IAnnotations):

       def __iter__():
           pass

       def __contains__():
           pass

Code that needs iteration or containment functionality can adapt to 
IIterableAnnotations. Adapters that actually provide those methods can 
register themselves as such (the attribute-annotations adapter will 
surely be able to do that).


-- 
http://worldcookery.com -- Professional Zope documentation and training
2nd edition of Web Component Development with Zope 3 is now shipping!


More information about the Zope3-dev mailing list