Skip to content

Await coroutine functions in timer decorators - #259

Open
FanWu-ai wants to merge 1 commit into
gruns:masterfrom
FanWu-ai:fix/await-async-timer
Open

FanWu-ai wants to merge 1 commit into
gruns:masterfrom
FanWu-ai:fix/await-async-timer

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 8, 2026

Copy link
Copy Markdown

The timer decorator currently wraps coroutine functions with a synchronous function. It prints a duration as soon as the coroutine object is created, before the function body runs. It also makes inspect.iscoroutinefunction() return False for the decorated function.

Use an asynchronous wrapper for coroutine functions and await the original function inside the timed try/finally. Timing is reported when execution returns, raises, or is cancelled. Synchronous functions retain their existing wrapper.

Add five deterministic regression/control tests covering deferred execution, coroutine-function detection and metadata, return values and keyword arguments, exception identity, disabled output, and cancellation. Three tests fail against the unmodified implementation. The README includes a coroutine example.

Validation on Linux, CPython 3.12.14:

  • Unmodified full unittest suite: 65 passed, no skips.
  • Final full unittest suite: 70 passed, no skips.
  • Project-pinned mypy 1.7.1: all five source files passed.
  • Source distribution and wheel build: passed.
  • git diff --check: passed.

The hosted Python/OS matrix has not been run locally.

Prepared with AI assistance.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 8, 2026 06:37
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

Successfully merging this pull request may close these issues.

1 participant