[Python-Dev] Re: metaclass and author are already decorators (original) (raw)
Phillip J. Eby pje at telecommunity.com
Sun Aug 22 01:12:57 CEST 2004
- Previous message: [Python-Dev] Re: __metaclass__ and __author__ are already decorators
- Next message: [Python-Dev] Re: __metaclass__ and __author__ are already decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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)'.
- Previous message: [Python-Dev] Re: __metaclass__ and __author__ are already decorators
- Next message: [Python-Dev] Re: __metaclass__ and __author__ are already decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]