[Zope3-dev] Re: calling interface returns object, calling queryAdapter returns None?

Laurence Rowe l at lrowe.co.uk
Wed Jan 24 15:56:42 EST 2007


Chris Withers wrote:
> Hot on the heels of my multi-adapter problem:
> 
> http://mail.zope.org/pipermail/zope3-dev/2007-January/021600.html
> 
> ...which I'm still waiting for guidance on, I now find that queryAdapter 
> and calling an interface behave unexpectedly differently in the case 
> where an object directly implements an interface:
> 
>  >>> from zope.interface import Interface,implements
>  >>> class ITest(Interface): pass
> ...
>  >>> class Test:
> ...   implements(ITest)
> ...
>  >>> t = Test()
>  >>> ITest(t)
> <__main__.Test instance at 0x01C6E300>
>  >>> from zope.component import queryAdapter
>  >>> queryAdapter(t,ITest)
>  >>>
> 
> How come calling the interface returns t but queryAdapter returns None?
> 
> Should I log this and my previous multi-adapter example as bugs in the 
> collector?
> 
> cheers,
> 
> Chris
> 

 From the Interface.__call__ docstring: "If an object already implements 
the interface, then it will be returned"

queryAdapter is looking in the adapter registry.

You have not registered any adapters.

So this looks like the expected behaviour to me.

Laurence



More information about the Zope3-dev mailing list