Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] kwargs are not respected #157

Open
mlguruz opened this issue May 10, 2023 · 3 comments
Open

[BUG] kwargs are not respected #157

mlguruz opened this issue May 10, 2023 · 3 comments

Comments

@mlguruz
Copy link

mlguruz commented May 10, 2023

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 ?

@micheles
Copy link
Owner

It is perfectly right. This is how argument passing works in Python, even without any decorator.

@mlguruz
Copy link
Author

mlguruz commented May 11, 2023

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) ?

@micheles
Copy link
Owner

Yes, but you are calling func(inputdir, tempdir, **k)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants