Decorators

Colin J. Williams cjw at sympatico.ca
Mon Aug 9 20:29:59 EDT 2004


Jeff Shannon wrote:
> Dan Bishop wrote:
> 
>> "Colin J. Williams" <cjw at sympatico.ca> wrote in message 
>> news:<%A8Rc.50217$Vm1.1280580 at news20.bellglobal.com>...
>>  
>>
>>> Christopher T. King suggested that "we're trying to kill too many 
>>> birds with one stone".
>>>
>>> http://groups.google.com/groups?q=stone+birds+group:comp.lang.python&hl=en&lr=&ie=UTF-8&selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu&rnum=1 
>>>
>>>
>>> He goes on to suggest three needs which decorators serve.  Are these 
>>> the only purposes which are envisaged for decorators?
>>>   
>>
>>
>> If I understand correctly, they'd be useful for anything where you'd
>> now use the syntax
>>
>> function = decorator(function)
>>  
>>
> 
> Many of the uses I'm seeing proposed for decorators would fit better 
> into the current syntax:
> 
> def func( ... )
>    pass
> dosomething(func)
> 
> In other words, they're not specifically changing the behavior of the 
> function, but they are using the (name and/or address of the) function 
> in some other context.  The modification of the function (or method) 
> itself is an unnecessary side effect.
It seems to me that PEP 318 is intended to be transformational, as in 
Dan Bishop's examples.

The purpose is to flag the transformation at the head of the function 
declaration, ie. to give notice to the reader that the function is not 
what it seems to be.

One of the issues is whether the flagging should occur before or after
the function signature.  I can see some merit in the flagging and feel
that it better after the signature, where the function name is, in a 
sense known.

Another issue is whether a single character or a keyword is used to
flag the 'decorator'.  One post suggested that the pie would be better 
used as a replacement for self.

There is also the question of whether 'decorator', a term which is used
in everyday langage as indicating adornment, is the best choice for a
transformation.

> Whether this distinction matters is obviously a purely aesthetic matter, 
> since obviously the decorator can rebind the name to the original 
> function object instead of a wrapping-function object.  But still, it 
> does suggest that this concept is indeed being put to multiple 
> orthogonal purposes.
> Jeff Shannon
> Technician/Programmer
> Credit International
> 
Colin W.




More information about the Python-list mailing list