Skip to content

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

@MagicFrogSJTU

Description

@MagicFrogSJTU

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions