[Grok-dev] Re: MultiAdapter doc bug?

Philipp von Weitershausen philipp at weitershausen.de
Tue Jun 24 05:04:47 EDT 2008

Graham Stratton wrote:
> The documentation in 
> http://svn.zope.org/grok/tags/0.13/doc/reference/components.rst implies 
> that you can get a multiadapter like this:
>  >>> home = IHome(cave, fireplace)
> I'm pretty sure this doesn't work.

As Tim said, this isn't a multi-adapter lookup. Single-adapter lookup 
with an interface is of the form

   iface(obj, default)

> It certainly isn't how we do the lookup in our tests:
>  >>> home = zope.component.getMultiAdapter((cave, fireplace))
> I think that if you want to specify the interface you're adapting to you 
> can do:
>  >>> home = zope.component.getMultiAdapter((cave, fireplace), IHome)
> To be honest I don't understand why you wouldn't want to specify the 
> interface you're adapting to.

Right. You should always specify the interface you're adapting to. If 
you don't, zope.interface.Interface is assumed.

Due to some very very old legacy, we look up views for 
zope.interface.Interface (instead of a dedicated publishing interface), 
which is why you may sometimes see code like this:

   getMultiAdapter((obj, request), name="foo.html")

(no interface specified, so z.i.Interface is the assumed default). 
HOpefully this will be changed soon.

> Assuming this is a bug I'll fix it if someone suggests which of the 
> above options is the preferred approach.

The preferred approach is to do

   getMultiAdapter((obj1, obj2, ..., objN), targetiface, name=...)

More information about the Grok-dev mailing list