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)'.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4