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

[feature request] function decorator timer should support direct call #15

Open
MagicFrogSJTU opened this issue Dec 7, 2020 · 1 comment

Comments

@MagicFrogSJTU
Copy link

Currently, it can only be

@timer()
def my_func():
    pass

But, the following code is expected to run but fail:

@timer
def my_func():
    pass

An fix can be easily done to decorator definition by

def example2(_func=None, *, kw1=val1, kw2=val2):
    if _func is None:
        return functools.partials(example2, kw1=val1, kw2=kw2) 
    
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        # do things with kw1
        return func(*args, **kwargs)
    return wrapper

I am willing to make a PR if it is needed.

@brouberol
Copy link
Owner

brouberol commented Dec 13, 2020 via email

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