There is a bug here: args is a tuple so it it is always hashable. You must check that each argument in args is hashable. You also need tests checking that the memoization is working as expected.