Decorators
Jeff Shannon
jeff at ccvcorp.com
Mon Aug 9 16:49:40 EDT 2004
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.
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
More information about the Python-list
mailing list