On Fri, 26 Aug 2005 18:40:07 +1000 Andrew Bennetts wrote:
On Fri, Aug 26, 2005 at 12:00:39PM +0400, email@example.com wrote:
If I, say, adapt WovenContext to ISession, I get a session object which does not implement the ISession interface itself. Absurdly.
Yep. But that's a trivially fixable bug in that adapter. And this is
Should it be considered as a bug then?
exactly why raising an exception would be bad -- it will break code that otherwise works fine. Even though such code is arguably buggy, Twisted
One could say that the code in question is already broken. At least, the exception would point to the programmer that they forgot to declare what interfaces are implemented by the adapter.
tries reasonably hard not to break backwards compatibility without warning. We couldn't raise CannotAdapt here without first giving DeprecationWarnings for at least one release.
Well, if raising CannotAdapt is not appropriate, then probably some decorator to AdapterFactory could help? Something like (pseudocode):
def affirm(adapterFactory, interface):
def safe_factory(orig): adapter = adapterFactory(orig) if not interface.providedBy(adapter): warn("Failed to adapt") adapter = MakeTheObjectToProvide(adapter, interface) return adapter
adapterFactory = affirm(adapterFactory, interface)