def runtime(f):
"""Evaluates the given function each time it is called."""
# get the function's name
name = f.__name__
# and its source code, sans decorator
source = remove_decorators(getsource(f))
@wraps(f)
def wrapped(*args, **kwargs):
# execute the function's declaration
exec(source)
# since the above overwrites its name in the local
# scope we can call it here using eval
return eval("%s(*%s, **%s)" % (name, args, kwargs))
return wrapped
评论列表
文章目录