[Zope3-dev] "Sub interface"

Jim Fulton jim at zope.com
Sun Feb 29 12:17:13 EST 2004


Terry Hancock wrote:
> I have researched the Wikis and ML archives regarding 
> interface implementations in Zope, and have not found
> anywhere the concept of a "sub-interface" which I 
> implemented because I found it indispensable in my
> product design.

But such a concept exists, even if it didn't make it to
the docs.

> A sub-interface inherits from Interface.Attribute, but
> has an extra property specifying the expected interface
> of the attribute.

You should look at zope.schema. See especially the README.txt
file there.

...

> I can provide detailed use-cases if they aren't obvious to 
> you, but here's just a suggestion:

No need. :)

...

> Anyway, the reason this came up is because I wrote it as an 
> extension to the "Interface" module provided in Zope 2.5.1. 
> That has changed extensively, and my code is now completely 
> broken in Zope 2.7 (it's beyond a few name fixes -- I need 
> to just rewrite the thing.  Fortunately it's less than 100 
> loc or so).

...

> So I want to answer the strategic question of how to 
> proceed with fixing this problem.  Should I:

... (options snipped)

None of the above. :)

First, you should Zope 3 interfaces.  As Martijn pointed out,
this is a bit harder than we'd like it to be in Zope 2.7 and
earlier. You need to:

- Arrange to have the zope.interface package in your Python
   path.

- Get the Interfaces "facade" package from Packages3/Interface
   in the repository. You need to arrange to have this ahead
   of the normal Zope 2 interface package in the Python path.

   The facade is needed to support Zope 2 software that expects the
   old Interface API.

Make your enhancements on top of the zope.interface package.

Second, you want to use zope.schems and the Object field, which
addresses your use cases, or should address them:


import zope.interface
import zope.schema


class IFoo(zope.interface.Interface)

   myattr = zope.schema.Object(schema=IBar)


> A cursory look at the Zope 2.7 Interface and Zope X3 
> interface modules suggests that they are pretty similar, 
> but not identical. 

Right.

 > How much change has gone on?

A fair bit.

 > Especially
> at the conceptual level where it will mean more than just 
> subbing a few names?

Yes.  See for example:

http://dev.zope.org/Zope3/BetterInterfaceImplements

although even this has evolved. See zope.interface.interfaces.

> Anyway, I'm looking for comments or advice on how to pursue 
> this.

An improvement I haven't had time to pursue is to generalize the
verification framework a bit, along the lines of the attribute
verification you've mentioned. Wanna help? :)

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