[Zope-dev] Two small convenience suggestions for zope.interface and zope.component
Marius Gedminas
marius at gedmin.as
Wed Apr 1 12:53:10 EDT 2009
On Wed, Apr 01, 2009 at 10:56:30PM +0800, Martin Aspeli wrote:
> Tres Seaver wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Martin Aspeli wrote:
> >> Hi,
> >>
> >> I'd like to add support for the following:
> >>
> >> 1) Provider decorator:
> >>
> >> @provider(IFoo)
> >> def some_function(context)
> >> pass
> >>
> >> This is an alternative to doing a separate alsoProvides() on the function.
> >>
> >> 2) An interfaceProvides directive:
> >>
> >>
> >> class IFoo(Interface):
> >> interfaceProvides(ISomeMarker)
> >>
> >> This is alternative to doing alsoProvides() on the interface.
> >>
> >> The reason for this is that currently, you have to put those
> >> alsoProvides() lines after the function or interface. This makes them
> >> difficult to find if the bodies of the functions or interfaces are long,
> >> and goes against the convention of having the "what is this" information
> >> at the top of the entity.
> >>
> >> I can probably help implement this. Any thoughts?
> >
> > You should probably add a "class decorator" 'interfaceProvider', as
> > well, because the "in-suite" versions are problematic for 2to3
> > conversion (IIRC what Lennart said yesterday).
>
> I'm not sure I understand what you mean by that. Can you show an example?
It's a Python 2.6/3.0 feature:
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.
I now also wonder if adapter()/implementer() would work when called with
classes rather than functions...?
Marius Gedminas
--
http://pov.lt/ -- Zope 3 consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20090401/dcf2a4d5/attachment.bin
More information about the Zope-Dev
mailing list