[Python-Dev] Class decorators

Gustavo Carneiro gjcarneiro at gmail.com
Wed Mar 29 15:41:08 CEST 2006


On 3/29/06, Phillip J. Eby <pje at telecommunity.com> wrote:
>
> At 11:35 PM 3/28/2006 -0500, Fred L. Drake, Jr. wrote:
> >For Zope 3, we have decorators that work with the component architecture
> (I'm
> >sure Phillip is familiar with these).  They're used with functions to
> >indicate that the function adapts a particular kind of object, or that it
> >implements or provides a particular interface.  We have different
> functions
> >that get used for this purpose in classes that are executed within the
> body
> >of the class.  There's some merit to being able to use a single set of
> >functions in both cases, since the use cases are the same.  I'm not sure
> I'd
> >want to change the existing pattern, though, since it's already so
> widespread
> >within the Zope 3 codebase (including 3rd-party components).
>
> If we're using Zope 3 as an example, I personally find that:
>
>      class Foo:
>          """Docstring here, blah blah blah
>          """
>          implements(IFoo)
>
> is easier to read than:
>
>      @implements(IFoo)
>      class Foo:
>          """Docstring here, blah blah blah
>          """



  Yeah, but in the first case implements(IFoo) has to do dirty hacks
involving sys.getframe(), so you win in once place but lose in the other
one.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060329/b8cb0c5d/attachment.html 


More information about the Python-Dev mailing list