Decorator Base Class: Needs improvement.

Scott David Daniels Scott.Daniels at Acm.Org
Tue Apr 5 17:32:59 EDT 2005


Ron_Adam wrote:
> What I was referring to is the case:
>     @decorator(x,y,z) 
> As being a decorator expression with more than one argument.  
But, we generally say this is a call to a function named decorator
that returns a decorator.  If you called it:
     @make_decorator(x,y)
     def .....
We'd be sure we were all on the same page.

How about this as an example:

     def tweakdoc(name):
         def decorator(function):
	    function.__doc__ = 'Tweak(%s) %r' % (name, function.__doc__)
	    return function
         return decorator

What is confusing us about what you write is that you are referring to
tweakdoc as a decorator, when it is a function returning a decorator.

> and not: 
>     @decorator(x)(y)

This is only prevented by syntax (probably a good idea, otherwise
we would see some very complicated expressions before function
declarations).

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list