[Twisted-Python] Components

James Y Knight foom at fuhm.net
Thu Feb 26 11:58:49 EST 2004

So I want to merge the changes from Nevow that allow lazy adapter  
registration via string arguments to registerAdapter:

However, doing this necessarily means the removal of the implicit  
super-interface feature, where twisted automatically registers  
StringRenderer for all super-interfaces of ITypedRenderer. As there is  
no way to look up the super-interfaces of a string at registerAdapter  
time (without loading up the module), this feature cannot stay.

I also doubt that's actually used by anyone. I can't think of a reason  
why I'd want to do that. The test suite doesn't even test it: all tests  
pass after removing it. There is a test for the behavior of the  
components.superInterfaces function, but not for actually registering  

Also, the current behavior is pretty much arbitrary and wrong:
from twisted.python.components import *

class IFoo(Interface):

class IBaz(IFoo):

class MyIFooAdapter(Adapter):

class MyIBazAdapter(Adapter):

registerAdapter(MyIBazAdapter, str, IBaz)
registerAdapter(MyIFooAdapter, str, IFoo)
Results in:
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "twisted/python/components.py", line 214, in registerAdapter
     raise ValueError(
ValueError: an adapter (__main__.MyIBazAdapter) was already registered.

registerAdapter(MyIFooAdapter, str, IFoo)
registerAdapter(MyIBazAdapter, str, IBaz)
works fine.
Depending on the order of adapter registration seems quite fragile to  
me. The only proper way to handle this would be to have a concept of  
'depth' ala PyProtocols.


More information about the Twisted-Python mailing list