Why won't this decorator work?

Tim Chase python.list at tim.thechases.com
Sat Jul 2 14:45:51 EDT 2011


On 07/02/2011 01:08 PM, John Salerno wrote:
> On Jul 2, 12:33 pm, MRAB<pyt... at mrabarnett.plus.com>  wrote:
>>       roll_die = move(roll_die)
>>
>> You should be defining a function (a callable) and then passing it to a
>> decorator which returns a callable.
>
> But why does the documentation say "The return value of the decorator
> need not be callable"?

I must not be looking at the same documentation you are...could 
you provide a link? The only time I know of that the return value 
of a decorator need not be callable is if you want to totally 
break the syntax of the function. :-/

> And why, if I remove the decorator and just leave the two
> functions as if, does the call to move(roll_die()) work? Isn't
> that what the decorator syntax is essentially doing?

Are you doing

   move(roll_die()) #call roll_die() and pass results to move()

or

   move(roll_die) # pass the function-object roll_die to move()

?  The decorator syntax is the equivalent of

   roll_die = move(roll_die)

-tkc






More information about the Python-list mailing list