[Twisted-Python] Disturbing aspect of zope.interface

Brian Granger ellisonbg.net at gmail.com
Thu Oct 8 19:23:39 EDT 2009


I know this is not the zope list, but I am encountering this in a twisted
project, so I
wanted to get some ideas here first.  I am finding that zope.interface is
an infectious disease.  Here is a simple example:

In [35]: import zope.interface as zi

In [37]: class A(object):
   ....:         pass

In [38]: class IB(zi.Interface):
   ....:         pass

In [39]: hasattr(A, '__provides__')
Out[39]: False

In [41]: # Inheriting from A gives A additional methods

In [42]: class B(A):
   ....:         zi.implements(IB)

In [43]: hasattr(A, '__provides__')
Out[43]: True

In [45]: # C is clean of the additional methods

In [46]: class C(object):
   ....:         pass

In [47]: hasattr(C, '__provides__')
Out[47]: False

The disturbing thing is that now A (which is just an object) has been hacked
by zope.interface.  It has additional methods (__provides__, etc.) that are
specific to

Summary: If a class A is later subclassed by something B that calls
zi.implements, the original class A
becomes infected with all the zope.interface stuff.

Is there a way to avoid this?  Doesn't this seem like a bad idea?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20091008/fd0ac4c5/attachment.htm 

More information about the Twisted-Python mailing list