[Python-Dev] Decorators with arguments are curries!
"Martin v. Löwis"
martin at v.loewis.de
Sat Aug 7 15:00:13 CEST 2004
Andrew Durdin wrote:
> def bar_decorator(func, param):
> print param
> return func
>
> @foo_decorator
> @bar_decorator("one param here")
> def decorated_func():
> pass
>
> Here the first decorator statement is bare, while the second one
> includes parentheses and an argument; the first one looks like a
> function reference, while the second looks like a function call.
Correct. And that is indeed the intended meaning. Did you try this
out? It gives
Traceback (most recent call last):
File "b.py", line 9, in ?
@foo_decorator
TypeError: bar_decorator() takes exactly 2 arguments (1 given)
(although, as you can see, the line number is off by one)
See
http://www.python.org/dev/doc/devel/ref/function.html
on why this is so.
> Most of my concern here is that this aspect of decorator syntax
> appears to be implicitly introducing a currying syntax in one special
> circumstance, which is then *not* transferable to currying functions
> in normal situations, as it would conflict with function calling.
And yet, the proposal does no such thing.
Regards,
Martin
More information about the Python-Dev
mailing list