[Python-Dev] Re: Re: Call for defense of @decorators
Skip Montanaro
skip at pobox.com
Tue Aug 10 14:56:27 CEST 2004
>> I think "adorn" would make a better keyword in that case, as in
>> "adorn with" this decorator the method foo.
Bob> I don't think that's appropriate at all. Most decorators are
Bob> transformations that change the function object into something else
Bob> entirely, most likely by wrapping it but quite possibly not.
Correctamundo. In fact, there's no need that the decorator return a
function (or callable) object at all. You could define a function to
compute a lookup table of some sort. The decorator might simply invoke the
function and return its value. Perfectly legal. Slightly more than
adornment. Somewhat silly example:
def define(func):
return func()
@ define
def grayscale():
table = []
for i in range(256):
table.append((i,i,i))
return table
Skip
More information about the Python-Dev
mailing list