decorator
decorator copied to clipboard
[BUG] kwargs are not respected
If I just ran the example from the doc:
from decorator import decorator
@decorator
def warn_slow(func, timelimit=60, *args, **kw):
print(kw)
t0 = time.time()
result = func(*args, **kw)
dt = time.time() - t0
if dt > timelimit:
logging.warn('%s took %d seconds', func.__name__, dt)
else:
logging.info('%s took %d seconds', func.__name__, dt)
return result
@warn_slow # warn if it takes more than 1 minute
def preprocess_input_files(inputdir, tempdir,):
...
preprocess_input_files(inputdir='a', tempdir='b')
print(kw)
shows empty dict, which It should not right ?
It is perfectly right. This is how argument passing works in Python, even without any decorator.
I'm sorry - I must be missing something obvious here:
If I call func(*a, **k) as func(inputdir='a', tempdir='b), shouldn't a = (), and k = dict(inputdir='a', tempdir='b) ?
Yes, but you are calling func(inputdir, tempdir, **k)