[Twisted-Python] Notes on switching twisted to new zope.interface code

Itamar Shtull-Trauring itamar at itamarst.org
Sun Jul 18 22:39:24 EDT 2004


1. Switch classes from:

  class C:
      __implements__ = IFoo,

to:

  class C:
      zope.interface.implements(IFoo)

and if you have third party subclasses that may depend on C having
__implements__, also add:

  twisted.python.components.backwardsCompatImplements(C)


2. Using zope.interface APIs directly is better, e.g. IFoo.providedBy(o)
rather than components.implements(o, IFoo). But! If the object is third
party, it may be using __implements__, and if the class never got
processed by t.p.c it will not be hooked up to zope.interface at all.
So, you may want to do:

   t.p.componets.fixClassImplements(o.__class__)

this will make sure that __implements__ declarations get converted to
new style implements declarations.

3. Basically all of t.p.c is deprecated except for registerAdapter and
the other APIs that talk to registry. Componentized is not, in theory,
but hopefully will be replaced soon.

-- 
Itamar Shtull-Trauring    http://itamarst.org






More information about the Twisted-Python mailing list