[Zope-dev] component registry navelgazing

Chris McDonough chrism at plope.com
Mon Jun 13 06:24:51 EDT 2011


On Mon, 2011-06-13 at 10:08 +0100, Chris Withers wrote:
> On 12/06/2011 21:48, Chris McDonough wrote:
> > Currently if you ask a registry to singly-adapt an object to an
> > interface, and the object you're trying to adapt implements that
> > interface, here's what happens:
> >
> >>>> from zope.component.registry import Components
> >>>> c = Components()
> >>>> from zope.interface import Interface, implements
> >>>> class IFoo(Interface): pass
> > ...
> >>>> class Foo(object):
> > ...     implements(IFoo)
> > ...
> >>>> foo = Foo()
> >>>> c.queryAdapter(IFoo, foo)
> > <None>
> 
> Looking back in history:
> 
> https://mail.zope.org/pipermail/zope-dev/2008-August/032902.html
> 
> I guess one or other of us has the parameter order wrong, probably me.
> 
> Much thread ensued:
> https://mail.zope.org/pipermail/zope-dev/2008-August/thread.html#32902
> https://mail.zope.org/pipermail/zope-dev/2008-September/thread.html#33174
> 
> Some justification for keeping the status quo from Fred:
> 
> https://mail.zope.org/pipermail/zope-dev/2008-September/033172.html
> 
> I stand by my resultant request here:
> 
> https://mail.zope.org/pipermail/zope-dev/2008-September/033170.html
> 
> Maybe less people care about ZCA now and so we might actually get 
> sensible changes made.

This argument against makes sense to me:

https://mail.zope.org/pipermail/zope-dev/2008-August/032908.html

So I've added a method to a subclass of
zope.component.registry.Components for my own purposes:

    def queryAdapterOrSelf(self, object, interface, default=None):
        provides = providedBy(object)
        if not interface in provides:
            return self.queryAdapter(object, interface, default=default)
        return object


- C




More information about the Zope-Dev mailing list