[Python-Dev] Class decorators

Fred L. Drake, Jr. fdrake at acm.org
Wed Mar 29 07:48:52 CEST 2006

On Wednesday 29 March 2006 00:01, Phillip J. Eby wrote:
 > 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:

I think the existing usage for classes is perfectly readable.  The @-syntax 
works well for functions as well.

 > For some reason, this doesn't bother me with functions.  But then, I can't
 > remember how often I've actually needed to use two decorators on the same
 > function, or how many times a function decorator's arguments took multiple
 > lines to list.

For zope.formlib actions, I find there's usually only one decorator.  
Sometimes it fits comfortably on one line, and sometimes it takes two or 

For component architecture decorators, we find we commonly use two 
(zope.interface.implementer and zope.component.adapter) in tandem.  This can 
be fairly verbose with multi-object adaptation, or really long package names.

 > It's too bad this syntax is ambiguous:
 >      class Foo:
 >          """Docstring here, blah blah blah
 >          """
 >          @implements(IFoo)
 > As this achieves a desirable highlighting of the specialness, without
 > forcing the decorator outside the class.  Oh well.

Agreed, but... guess we can't have everything.  On the other hand, something 

    class Foo:
        """Documentation is good."""

        @class implements(IFoo)

is not ambiguous.  Hmm.  It even says what it means.  :-)


Fred L. Drake, Jr.   <fdrake at acm.org>

More information about the Python-Dev mailing list