Loading ...
Sorry, an error occurred while loading the content.

[Zope-dev] improving the utility and adapter lookup APIs

Expand Messages
  • Martijn Faassen
    Hi there, Reading the thread Chris McDonough started (and ended) about modifying the way utility registration works reminded me of the following thinking. It s
    Message 1 of 56 , Nov 25, 2009
    View Source
    • 0 Attachment
      Hi there,

      Reading the thread Chris McDonough started (and ended) about modifying
      the way utility registration works reminded me of the following
      thinking. It's quite independent and probably even antithetical to
      Chris's approach as it uses interfaces, but that's fine.

      The goal is to make it easier to look up certain componenty things. The
      goal is to have to import from "zope.component" as little as possible
      for lookups. Just import interfaces and you'll be done. I think it makes
      sense to make the lookup operation disappear into the "language" as much
      as we can make them.

      I know we've had this kind of discussion before, but let's get something
      working this time around. So I'm also looking for volunteers to help out
      with the implementation.

      I'm going to ignore registration APIs for now in this discussion. While
      they can be improved too, we have ZCML and martian-style registration
      systems that can handle that ok. Let's focus on lookup APIs first.

      We have a nice way to look up a single adapter:

      from foo import IFoo

      IFoo(object)

      Unfortunately, this breaks down when you want to look up a multiadapter:

      from foo import IFoo
      from zope import component

      component.getMultiAdapter((x, y), IFoo)

      That's an extra import and a lot more typing.

      We also have it break down when you want to look up a utility:

      from zope import component

      component.getUtility(IFoo)

      So let's look at ways to hook this up to interfaces.

      Adapter:

      IFoo(x)

      Adapter with default:

      IFoo(x, default=default)

      So far it's all supported. (I think. It's hard to find the code that
      supports this.. hints?)

      Named adapter:

      IFoo(x, name='something')

      Multiadapter:

      IFoo.multi(x, y)

      Multiadapter with default:

      IFoo.multi(x, y, default=default)

      Named multiadapter:

      IFoo.multi(x, y, name='something')

      Utility:

      IFoo.utility()

      [or possibly IFoo() instead?]

      Utility with default:

      IFoo.utility(default=default)

      [or IFoo(default=default)?]

      Named utility:

      IFoo.utility(name='something')

      [or IFoo(name='something')?]

      As a final thought, I don't like having to import 'implements' from
      zope.interface either. Since we're moving to Python 2.6 which supports
      class decorators, I'd like to see something like this become possible:

      @...
      class Foo(object):
      pass

      I know Jim had some objections towards implementation of this in an
      earlier discussion, but later changed his mind. So I'm going to look at
      Jim for hints about implementing this. :)

      If we do well we might all have this for Christmas. :)

      Thoughts?

      Regards,

      Martijn

      _______________________________________________
      Zope-Dev maillist - Zope-Dev@...
      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 )
    • Marius Gedminas
      ... Occasionally I ve missed a getNextAdapter() call too. Marius Gedminas -- http://pov.lt/ -- Zope 3 consulting and development
      Message 56 of 56 , Dec 3, 2009
      View Source
      • 0 Attachment
        On Thu, Dec 03, 2009 at 07:44:54AM +0100, Christian Theune wrote:
        > That reminds me that I had the occasional wish to invoke the ZCA using
        > some kind of chaining mechanism so that an adapter can ask for the next
        > less specific adapter that would have been invoked if the former wasn't
        > there. The use case is similar: delegate to a default.

        Occasionally I've missed a getNextAdapter() call too.

        Marius Gedminas
        --
        http://pov.lt/ -- Zope 3 consulting and development
      Your message has been successfully submitted and would be delivered to recipients shortly.