[feature request] function decorator `timer` should support direct call

Open
#15 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

Start at the timer decorator definition and compare how it handles @timer() with the direct @timer form shown in the issue. Confirm that both decorator usages run successfully while preserving the wrapped function behavior, then check the project's existing tests if available.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
73
Forks
11
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from brouberol/contexttimer

All issues in brouberol/contexttimer

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.