[feature request] function decorator `timer` should support direct call
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.
Hi!
I think it's a good idea, and if you have a PR at the ready, I'd be more than happy to merge it.
Thanks!
On Mon, Dec 7, 2020, at 10:03 AM, yzchen wrote:
Currently, it can only be
@timer() def my_func(): passBut, the following code is expected to run but fail:
@timer def my_func(): passAn 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.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/brouberol/contexttimer/issues/15, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADVHA3INQZIOML6HR2XSL3STSK5FANCNFSM4UQERWSQ.