[Python-Dev] Class decorators

Phillip J. Eby pje at telecommunity.com
Wed Mar 29 19:27:29 CEST 2006

At 12:48 AM 3/29/2006 -0500, Fred L. Drake, Jr. wrote:
>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.  :-)

Interesting.  I might have to rename some of my decorators to read well 
that way, though.  I'll play around with the idea a bit.

Of course, one of my use cases for class-level declarations is to work 
around the fact that decorators can't be applied to arbitrary attributes of 
a class, only to methods.  Hm.  Let me see:

   class SomeThing:
      """Some docs"""

      @class security.permissions(
          foo = security.Anybody,
          bar = myapp.User,

   class SomeCommand:
      """usage: some_command [-v|-q] [-f FILENAME] ..."""

      @class options.accept(
         verbose = [
            options.Set('-v', '--verbose', value=True, help="Be loud"),
            options.Set('-q', '--quiet', value=False, help="Be quiet")
         filename = [
            options.Set('-f', '--file', type=str, metavar="FILENAME")

Not bad.  Not bad at all.

More information about the Python-Dev mailing list