[Python-Dev] method decorators (PEP 318)

Jack Diederich jack at performancedrivers.com
Fri Mar 26 11:08:32 EST 2004


On Fri, Mar 26, 2004 at 07:10:34AM -0800, Guido van Rossum wrote:
> We came to an interesting conclusion (which Robert had anticipated):
> there are two quite different groups of use cases.
>
> The other group of use cases merely attaches extra bits of metadata to
> the method, without changing its usage.  That is what most C# and Java
> decorators are used for.
I've posted some examples in the 318 threads of both kinds,
the function decorators I use tend to change behavior and
the class decorators I use tend to be meta-markup.

For class decorators I currently use a work around w/ metaclasses,
I don't decorate functions much so I just do it the old fashioned way.

> So, anyway, here's a new suggestion (inspired by Robert's proposal):
> (2) Invent some other notation for setting function attributes as part
>     of the function *body*, before the doc string even.
> 
> For (2) I am thinking aloud here:
> 
>    def foobar(self, arg):
>        @author: "Guido van Rossum"
>        @deprecated
>        pass

I'm agnostic on '@' but this looks like pydoc markup to me, what about

def foobar(self, arg):
  @author = "Guido van Rossum"
  @deprecated = True

People will also want to access these, so also consider how this will read:

def foobar(self, arg):
  @author = "Guido"
  @email = @author.lower() + '@python.org' # contrived example

I'd be a little worried that new users from other languages would start
using '@' as a synonym for 'this' in strange ways.  Nothing that can't
be remedied with a clue bat.

-jackdied





More information about the Python-Dev mailing list