I'm trying to learn decorators and partial, and I think I make some sense. I understand decorators as a way to add additional functionality to an object by passing in the arguments from the function that calls the decorator into the nested function in the decorator. My understanding of partial is that I can use when I want to reduce the number of parameters to a function. So far so good. But then I saw this code snippet, and I don't understand why _inner
takes in only start
and end
. Why not pos
? In my head, it makes sense if this should be the third parameter. :
def annealer(f):
def _inner(start, end):
return partial(f, start, end)
return _inner
@annealer
def sched_lin(start, end, pos):
return start + pos*(end-start)
f = sched_lin(1,2)
f(1)
OUTPUT: 2