def memoize(fun):
@funcutils.wraps(fun)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>do_memoization = sportsref.get_option('<STR_LIT>')<EOL>if not do_memoization:<EOL><INDENT>return fun(*args, **kwargs)<EOL><DEDENT>hash_args = tuple(args)<EOL>hash_kwargs = frozenset(sorted(kwargs.items()))<EOL>key = (hash_args, hash_kwargs)<EOL>def _copy(v):<EOL><INDENT>if isinstance(v, pq):<EOL><INDENT>return v.clone()<EOL><DEDENT>else:<EOL><INDENT>return copy.deepcopy(v)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>ret = _copy(cache[key])<EOL>return ret<EOL><DEDENT>except KeyError:<EOL><INDENT>cache[key] = fun(*args, **kwargs)<EOL>ret = _copy(cache[key])<EOL>return ret<EOL><DEDENT>except TypeError:<EOL><INDENT>print('<STR_LIT>'<EOL>.format(fun.__name__, key))<EOL>raise<EOL><DEDENT><DEDENT>cache = {}<EOL>return wrapper<EOL>
A decorator for memoizing functions.

    Only works on functions that take simple arguments - arguments that take
    list-like or dict-like arguments will not be memoized, and this function
    will raise a TypeError.