projects.py: Fix cache_func(), evaluated one key short of what it should have

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-08-09 14:25:15 +00:00
commit 42e8e6522d

View file

@ -30,22 +30,24 @@ def err(*objs):
def cache_func(func, args): def cache_func(func, args):
d = cache d = cache
depth = 0 depth = 0
for a in [ func.__name__ ] + args: keys = [ func.__name__ ] + args
if a is None: l = len(keys)
a = 'None' for k in keys:
if k is None:
k = 'None'
depth += 1 depth += 1
#debug('depth = ', depth, 'arg = ', a, 'd = ', str(d)) #debug('depth = ', depth, 'key = ', k, 'd = ', str(d))
if a in d: if k in d:
if len(args) == depth: if l == depth:
return d[a] return d[k]
d = d[a] d = d[k]
continue continue
if len(args) == depth: if l == depth:
r = func(*args) r = func(*args)
d[a] = r d[k] = r
return r return r
d[a] = {} d[k] = {}
d = d[a] d = d[k]
raise Exception("cache algorithm failed for function", func.__name__, "in depth", depth) raise Exception("cache algorithm failed for function", func.__name__, "in depth", depth)
def proj_dir(name): def proj_dir(name):