Current

This document is valid for the current version of Plone.

No more Zope 2 interfaces

by Plone Documentation Team last modified Aug 21, 2010 11:29 AM
Versions of Zope 2 prior to Zope 2.12.0 supported two types of interfaces (the old Zope 2 implementation and the new Zope 3 implementation from zope.interface). Now only the latter remains.

In Plone 2.5 and Plone 3, Zope contained two different ways of declaring that a class implements a particular interface.

Zope 2 style
from Interface import Interface

class MyInterface(Interface):
    pass

class MyClass(object):
    __implements__ = (MyInterface,)
Zope 3 style
from zope.interface import Interface

class MyInterface(Interface):
    pass

class MyClass(object):
    implements(MyInterface)

In Zope 2.12, only Zope 3 style interfaces are supported.

Code trying to define Zope 2 interfaces will raise the following exception:

ImportError: No module named Interface

Zope 2 style interfaces removed from ATContentTypes

In Plone 3, the Zope 2 style interfaces were defined in interfaces.py and the Zope 3 ones in the interface folder.

In Plone 4, the Zope 2 style interfaces have been removed and the Zope 3 ones moved to the interfaces submodule, to follow naming conventions. However, a link to these Zope 3 interfaces has been left in interface.py, so the following example code will work in both Plone 3 and 4:

from Products.ATContentTypes.interface import IATFolder

Trying to use implements() with Zope 2 style interfaces will fail.