def index(self):
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Fri Dec 22 02:48:18 EST 2006
In <mailman.1929.1166742467.32031.python-list at python.org>, Gert Cuykens
wrote:
> On 21 Dec 2006 09:44:48 GMT, Duncan Booth <duncan.booth at invalid.invalid> wrote:
>> "George Sakkis" <george.sakkis at gmail.com> 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
More information about the Python-list
mailing list