[Twisted-Python] Yet another coil refactor

Itamar Shtull-Trauring twisted at itamarst.org
Tue Apr 9 00:59:14 MDT 2002


Glyph Lefkowitz wrote:

> So I propose a compromise: I think that classes which implement
> interfaces should be required to inherit from an Implementor class, in
> order to facilitate evolution of interfaces.  This Implementor class
> could even be a metaclass, ensuring at least trivial implementation
> constraints at import-time, possibly spotting bugs early on.

First of all, runtime checking can only catch gross miscompliance of 
interfaces. However, since interfaces talk about external APIs, not internal 
representation, changes to the interface are much less likely, esp. once we 
hit a stable release.

That is, someone currently writing for Twisted has to say - "this is for 
Twisted 0.15.5" or whatever, because we do have occasional changes of 
underlying interfaces, e.g. coil ;). Once we hit 1.0 the interfaces will 
*not* change in the stable branch.

So, we really just need to list any changes to interfaces in the changelog - 
there's no real way we can fix other people's code. I don't see how this is 
any different than the previous way things worked where we had implicit 
interfaces that changed (e.g. addShutdown was removed from t.i.main).


Next, conside this - we add these two functions to components module:

def registerImplementor(klass):
     """Register a class that implements interfaces."""

def addInterface(klass, interface):
     """Register that the class implements an interface not listed in
        its __implements__."""

and we would require this for any methods that wants to work with the 
components thing.

Benefits:
1. Checking of interface compliance can be done in an easier fashion (and I 
  already have the code for it).

2. The ability to add interfaces without sticking them in __implements__ - 
this could help solve the issue where twisted.web.resource depends on coil.

3. No need to mess with meta-classes, and it'll work pre-2.2 (and if you 
want to use pre-2.2 meta-classes, you're even crazier than previously thought ;)

Disadvantages:
*Possibly* need to add an extra line for each class, not just inherit in 
super-classes. However, if we implement addInterface() so that it mutates 
the __implements__, this won't be necessary, you'll only need to register 
the superclass.

This implies that registerImplementor is basically only used for testing 
interface compliance and can't have other side effects.






More information about the Twisted-Python mailing list