def boundedMemoize(arg):
    if callable(arg):
        cache = BoundedOrderedDict()

@functools.wraps(arg)
def memo_target(*args):
    lookup_value = args
if lookup_value not in cache:
    cache[lookup_value] = arg(*args)
return cache[lookup_value]
return memo_target
if isinstance(arg, int):

    def memoize(function):
        cache = BoundedOrderedDict(maxlen=arg)

@functools.wraps(function)
def memo_target(*args):
    lookup_value = args
if lookup_value not in cache:
    cache[lookup_value] = function(*args)
return cache[lookup_value]
return memo_target
return memoize
Как создать ограниченный декоратор мемоизации в Python?