Re: component registry navelgazing

Jim Fulton <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
On Sun, Jun 12, 2011 at 4:48 PM, Chris McDonough <[email protected]> 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>
>
> In order to get the object itself back from such an adaptation, you need
> to use the default= argument.
>
>>>> c.queryAdapter(IFoo, foo, default=foo)
> <__main__.Foo object at 0x24a3910>
>
> This seems slightly inconsistent with the adaptation worldview imposed
> by getAdapter/queryAdapter.  I think it would be more consistent if
> "c.queryAdapter(IFoo, foo)" returned foo if foo already implemented IFoo
> and there was no other more specific adapter registered for the IFoo/foo
> pair in the registry, no?

I don't know what getAdapter/queryAdapter you're referring to in
"This seems slightly inconsistent with the adaptation worldview imposed
by getAdapter/queryAdapter."

Do you mean " This seems slightly inconsistent with the adaptation
worldview imposed
by interface __call__." ?

Jim

-- 
Jim Fulton
http://www.linkedin.com/in/jimfulton
_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.