Say I have a function that modifies a list argument and a memoizer decorator, such as:
@memoizer
def add_1_to_list(list):
for i in range(len(list)):
list[i] += 1
return list
In my main program, I have
list = [1, 1, 1, 1]
add_1_to_list(list)
print list
If my memoizer class only caches the return values and sets add_1_to_list to return the same value, then when I run the main program the first time, it will print [2, 2, 2, 2], while the second time, it will print [1, 1, 1, 1], since list is mutable.
Are there any solutions to get a memoizer class to detect that the function modifies an argument, that way we can note it and save modified arguments? I was able to see it visually by printing the argument before and after calling it in the memoizer class, but without knowing what type the arguments are and whether they are mutable/immutable, it seems difficult to test whether an argument has been modified or not.