In <[EMAIL PROTECTED]>, Gert Cuykens
wrote:
> On 21 Dec 2006 09:44:48 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote:
>> "George Sakkis" <[EMAIL PROTECTED]> wrote:
>>
>> @expr
>> def fn(...): ...
>>
>> is exactly equivalent to:
>>
>> def fn(...): ...
>> fn = (expr)(fn)
>>
>
> ok i did my homework reading about decorators
> http://www.python.org/doc/2.4.4/whatsnew/node6.html
>
> could it be the example above needs to be like
>
> @expr
> def fn(...): ...
>
> is exactly equivalent to:
>
> def fn(...): ...
> fn = expr(fn)
This depends on the definition of `expr`. If `expr` includes the
possibility of enclosing parenthesis then yes. There are scenarios where
you would need them. For example if you use objects that overload
operators to build a callable used as decorator:
@spam + eggs + viking
def fn(...): ...
This would not be equivalent to:
def fn(...): ...
fn = spam + eggs + viking(fn)
but:
def fn(...): ...
fn = (spam + eggs + viking)(fn)
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list