[Twisted-Python] Interfaces and adapters

Andrew Bennetts andrew-twisted at puzzling.org
Fri Aug 26 04:47:36 EDT 2005

On Fri, Aug 26, 2005 at 12:54:47AM -0700, Bob Ippolito wrote:
> On Aug 25, 2005, at 11:30 PM, Andrew Bennetts wrote:
> >
> >That's a pretty reasonable expectation.  I think emitting a warning  if
> >this doesn't hold would be a sane thing to do, and it wouldn't break any
> >code.
> It would certainly slow it down, though.  I think this is a  
> "consenting adults" kind of scenario.  If someone registers an  
> adapter, they probably didn't do it by accident!

Right.  The bug the OP has here isn't that the adapter shouldn't have been
registered, but that the adapter fails to properly declare what interfaces
it provides, so that the result of IBar(IFoo(x)) will fail even though x ->
IFoo and IFoo -> IBar adapters are registered.

The performance question is important... benchmarks of any changes here
would be a good idea.

A weaker solution would be to only check at registration time, but that's
uglier, because it only works for adapters that are classes, and that don't
have creative __new__ methods.  That's almost certainly 99% of adapters, but
ugly and incomplete solutions make me nervous.

Anyway, the underlying zope.interface machinery allows this -- and includes
doctest documentation that relies on this (it registers *ints* as adapters,
iirc!).  I'm inclined to agree with your "consenting adults" approach, but I
don't feel strongly either way.


More information about the Twisted-Python mailing list