(func)
return wrapper
caching decorator.

       important: the result of cached function must be *immutable*


       Examples
       ========

       >>> from sympy.core.cache import cacheit
       >>> @cacheit
       ... def f(a,b):
       ...    return a+b

       >>> @cacheit
       ... def f(a,b):
       ...    return [a,b] # <-- WRONG, returns mutable object

       to force cacheit to check returned results mutability and consistency,
       set environment variable SYMPY_USE_CACHE to 'debug'
caching decorator.
caching decorator .
def __cacheit(func):
    """caching decorator.

       important: the result of cached function must be *immutable*


       Examples
       ========

       >>> from sympy.core.cache import cacheit
       >>> @cacheit
       ... def f(a,b):
       ...    return a+b

       >>> @cacheit
       ... def f(a,b):
       ...    return [a,b] # <-- WRONG, returns mutable object

       to force cacheit to check returned results mutability and consistency,
       set environment variable SYMPY_USE_CACHE to 'debug'
    """

    func._cache_it_cache = func_cache_it_cache = {}
    CACHE.append((func, func_cache_it_cache))

    @wraps(func)
    def wrapper(*args, **kw_args):
        """
        Assemble the args and kw_args to compute the hash.
        """
        k = [(x, type(x)) for x in args]
        if kw_args:
            keys = sorted(kw_args)
            k.extend([(x, kw_args[x], type(kw_args[x])) for x in keys])
        if _globals:
            k.extend([tuple(g) for g in _globals])
        k = tuple(k)

        try:
            return func_cache_it_cache[k]
        except (KeyError, TypeError):
            pass
        r = func(*args, **kw_args)
        try:
            func_cache_it_cache[k] = r
        except TypeError: # k is unhashable
            # Note, collections.Hashable is not smart enough to be used here.
            pass
        return r
    return wrapper
def __cacheit ( func ) : func . _cache_it_cache = func_cache_it_cache = { } CACHE . append ( ( func , func_cache_it_cache ) ) @ wraps ( func ) def wrapper ( * args , * * kw_args ) : """
        Assemble the args and kw_args to compute the hash.
        """ k = [ ( x , type ( x ) ) for x in args ] if kw_args : keys = sorted ( kw_args ) k . extend ( [ ( x , kw_args [ x ] , type ( kw_args [ x ] ) ) for x in keys ] ) if _globals : k . extend ( [ tuple ( g ) for g in _globals ] ) k = tuple ( k ) try : return func_cache_it_cache [ k ] except ( KeyError , TypeError ) : pass r = func ( * args , * * kw_args ) try : func_cache_it_cache [ k ] = r except TypeError : # k is unhashable # Note, collections.Hashable is not smart enough to be used here. pass return r return wrapper