Suppose that we create a decorator named deftime
Consider the following piece of code:
def LouiseTheLow(*ignore, **kw_ignore):
print("I am Oldy McMold Face")
@deftime
def HarriettTheHigh(*ignored_args, **ignored_keywords):
LouiseTheLow(59, "some stuff")
###################################################################
def LouiseTheLow(*ignore, **kwignore):
print("I am The Newest Latest Greatest Thing")
ret_val = HarriettTheHigh() # function call
I expect the above code to print "I am Oldy McMold Face"
Without the decorator, we would see: "I am The Newest Latest Greatest Thing"
Our goal is to write a decorator which causes a function to use the variables which existed when the function was defined, not when the function is called.
Please do not assume that the only variable of interest is named LouiseTheLow
.
The decorator should be general enough that other variable names can be used.
I have a lot of trouble with lambda functions getting clobbered.
def caller():
radius = 10
lamby = lambda height: height*radius**2
ret_val = callee(lamby, 1, 2, 3)
return ret_val
The problem is that callee
will often define a local variable which shadows the original variables used inside of the lambda function. In the example above, radius
might get clobbered.