[Python-Dev] Re: __metaclass__ and __author__ are already decorators
Paul Morrow
pm_mon at yahoo.com
Sun Aug 22 01:25:30 CEST 2004
Phillip J. Eby wrote:
> At 06:54 PM 8/21/04 -0400, Paul Morrow wrote:
>
>> Thanks. Of the 5 examples there, the first two are apparently not
>> implemented correctly, as they expect that the function/class to be
>> decorated is passed directly to them, rather than to the function they
>> return. Would you agree? I pasted them here for your consideration...
>
>
> They're correct. You're missing the fact that '@x' and '@x()' are not
> the same thing. '@x' means 'func=x(func)', while '@x()' means 'func =
> x()(func)'. There's no inconsistency here at all, it's just ordinary
> Python semantics.
>
> The only time a decorator needs to return a function is if it needs
> arguments other than the function being decorated. In which case, it
> might properly be termed a decorator factory, i.e. a function returning
> a decorator. Thus, in the '@' syntax, a decorator expression is always
> either '@decorator' or '@decorator_factory(arguments)'.
>
That's clear. Thank you.
More information about the Python-Dev
mailing list