[Twisted-Python] Interfaces and adapters
andrew-twisted at puzzling.org
Fri Aug 26 02:30:26 EDT 2005
On Fri, Aug 26, 2005 at 10:17:07AM +0400, en.karpachov at ospaz.ru wrote:
> Let's say we defined an interface and an adapter:
> class IFoo(zope.interfaces.Interface):
> twisted.python.components.registerAdapter(Foo, Bar, IFoo)
> As it is for now, the registerAdapter accepts any Foo, without regarding
> what it implements.
It has to accept pretty much anything -- adapters can be e.g. functions as
well as classes.
> Could somebody give any rationale why this condition shouldn't always hold:
> foo = IFoo(bar)
> assert IFoo.providedBy(foo)
> Seems it is not unreasonable to expect this behaviour, because it is
> exactly what interfaces are all about, or am I wrong?
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.
More information about the Twisted-Python