Update utils.py

This commit is contained in:
Piotr Mardziel
2024-11-05 13:34:09 -08:00
committed by GitHub
parent 6ff19dc232
commit f18ff6a87e

View File

@@ -1,11 +1,13 @@
from itertools import wraps
def memoize(func):
cache = {}
@wraps(func)
def memoized_func(*args, **kwargs):
key = (args, tuple(kwargs.items()))
if key not in cache:
cache[key] = func(*args, **kwargs)
return cache[key]
memoized_func.__dict__.update(func.__dict__)
return memoized_func