[Zope-dev] Two small convenience suggestions for zope.interface and zope.component
Martin Aspeli
optilude+lists at gmail.com
Wed Apr 1 13:09:39 EDT 2009
Hi Marius,
> It's a Python 2.6/3.0 feature:
Oh... sniff... I so want that. ;)
> from zope.component import adapter
> from zope.interface import implementer
>
> @adapter(IFoo)
> @implementer(IBar)
> class MyClass(object):
>
> def __init__(self, context):
> self.context = context
> ...
>
> which translates to the obvious
>
> class MyClass(object):
>
> def __init__(self, context):
> self.context = context
> ...
>
> MyClass = implementer(IBar)(MyClass)
> MyClass = adapter(IFoo)(MyClass)
>
> assuming I got the application order right.
Great.
> I now also wonder if adapter()/implementer() would work when called with
> classes rather than functions...?
I would hope so, or it'd be really confusing. :)
Martin
--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book
More information about the Zope-Dev
mailing list