(func)
return wrapper
cacheit + code to check cache consistency
cacheit + code to check cache consistency
cacheit + code to check cache consistency
def __cacheit_debug(func):
    """cacheit + code to check cache consistency"""
    cfunc = __cacheit(func)

    @wraps(func)
    def wrapper(*args, **kw_args):
        # always call function itself and compare it with cached version
        r1 = func(*args, **kw_args)
        r2 = cfunc(*args, **kw_args)

        # try to see if the result is immutable
        #
        # this works because:
        #
        # hash([1,2,3])         -> raise TypeError
        # hash({'a':1, 'b':2})  -> raise TypeError
        # hash((1,[2,3]))       -> raise TypeError
        #
        # hash((1,2,3))         -> just computes the hash
        hash(r1), hash(r2)

        # also see if returned values are the same
        if r1 != r2:
            raise RuntimeError("Returned values are not the same")
        return r1
    return wrapper
def __cacheit_debug ( func ) : cfunc = __cacheit ( func ) @ wraps ( func ) def wrapper ( * args , * * kw_args ) : # always call function itself and compare it with cached version r1 = func ( * args , * * kw_args ) r2 = cfunc ( * args , * * kw_args ) # try to see if the result is immutable # # this works because: # # hash([1,2,3])         -> raise TypeError # hash({'a':1, 'b':2})  -> raise TypeError # hash((1,[2,3]))       -> raise TypeError # # hash((1,2,3))         -> just computes the hash hash ( r1 ) , hash ( r2 ) # also see if returned values are the same if r1 != r2 : raise RuntimeError ( "Returned values are not the same" ) return r1 return wrapper