[Python-Dev] Re: Decorators with arguments are curries!

Guido van Rossum guido at python.org
Sat Aug 7 18:29:44 CEST 2004


> The primary issues were: (1) That decorators with vs. without
> arguments look inconsistent, like function calls vs. function
> references, and (2) that consequentially, decorator syntax is
> implicitly introducing a non-viable currying syntax.

I think you're mistaken.  When using @foo, foo should be a function
taking one argument; when using @foo(x,y,z), the *call* to foo(x,y,z)
should return a function of one argument (or an equivalent callable
object, of course).  This is often done by defining an inner "helper"
function, e.g.:

    def funcattrs(**kwds):
	def helper(func):
	    func.__dict__.update(kwds)
	return helper

    @funcattr(counter=42, obsolete=True)
    def foobar():
	pass

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list