Skip to content

Rename Timer to MonotonicTimer - #590

Merged
llucax merged 4 commits into
frequenz-floss:v1.x.xfrom
llucax:monotonic-timer
Nov 6, 2026
Merged

llucax merged 4 commits into
frequenz-floss:v1.x.xfrom
llucax:monotonic-timer

Conversation

@llucax

@llucax llucax commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Timer uses the event loop's monotonic clock; the new name says so and frees Timer for a wall clock timer (#584). Timer stays as a deprecated alias (deprecated_aliases(), since v1.13.0) until v2.0.0 (#365), and its warning says the name will come back as a wall clock timer.

I kept an alias instead of the deprecated subclass the deprecations guide suggests for types users construct: with a subclass, a MonotonicTimer isn't a Timer, so code migrated piece by piece (an updated library feeding a not-yet-updated app) would get type errors and failing isinstance() checks, not just deprecation warnings.

Fixes #582.

@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:synchronization Affects the synchronization of multiple sources (`select`, `merge`) part:utilities Affects the utility receivers (`Timer`, `Event`, `FileWatcher`) labels Nov 5, 2026
@llucax
llucax requested a balanced review from Copilot November 5, 2026 14:56
@llucax
llucax marked this pull request as ready for review November 5, 2026 14:57
@llucax
llucax requested a review from a team as a code owner November 5, 2026 14:57
@llucax
llucax requested review from daniel-zullo-frequenz and shsms and removed request for a team November 5, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Moving Timer behind __getattr__ without adding it to __all__ breaks existing wildcard imports, causing NameError instead of a deprecation warning.

1 open issue
What changed in this PR

Renames the monotonic-clock receiver to MonotonicTimer, preparing the Timer name for a future wall-clock implementation. The old name remains a deprecated alias intended to preserve compatibility until v2.0.0.

Changes:

  • Rename the class and add the deprecated alias without changing timer behavior.
  • Update documentation, examples, and existing tests to use MonotonicTimer.
  • Add tests for alias identity, deprecation warnings, and warning-free construction.
File Description
tests/​test_timer.py Migrate timer tests and add deprecation checks.
tests/​test_timer_integration.py Use the renamed timer in integration tests.
tests/​test_file_watcher_integration.py Update timer usage in file-watcher tests.
src/​frequenz/​channels/​timer.py Rename the class, add the alias, and update API documentation.
src/​frequenz/​channels/​_select.py Update the timer example in the docstring.
src/​frequenz/​channels/​__init__.py Update the receiver overview documentation.
RELEASE_NOTES.md Document migration and planned alias removal.
README.md Update example imports and timer construction.
docs/​user-guide/​utilities/​timers.md Point the user guide to MonotonicTimer.

Review effort: Balanced

Comment thread src/frequenz/channels/timer.py Resolved
shsms
shsms previously approved these changes Nov 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the timer rename and deprecated compatibility alias.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

`Timer` uses the event loop's monotonic clock, which the name doesn't
say. Renaming it makes that explicit and frees the name `Timer` for a
wall clock timer in a later version.

`Timer` stays as a deprecated alias made with `deprecated_aliases()`,
so it is the very same class and existing code keeps working, including
`isinstance()` checks and type annotations mixing both names. The
deprecations guide suggests a separate deprecated subclass for types
users construct, which type checkers would report, but then a
`MonotonicTimer` created by updated code wouldn't be a `Timer` for code
not updated yet, and users would get type errors, not only deprecation
notices, while migrating. The warning also says the name will be reused,
so users don't think it is gone for good.

Every use in the code, docstrings and tests now uses `MonotonicTimer`.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
`Timer` is now a deprecated alias, so point the examples and the timers
page at its new name.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Explain the rename of `Timer` to `MonotonicTimer`, why it happened and
how to migrate.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax llucax self-assigned this Nov 5, 2026
`Timer` is now only reachable through the module `__getattr__`, and
without an `__all__` a star import only picks up names defined in the
module, so `from frequenz.channels.timer import *` silently stopped
providing `Timer`, failing later with a `NameError` instead of a
deprecation warning.

List every public name, `Timer` included: a star import looks up each
name in `__all__`, which goes through `__getattr__` and warns.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax
llucax added this pull request to the merge queue Nov 6, 2026
Merged via the queue into frequenz-floss:v1.x.x with commit 786eaf5 Nov 6, 2026
9 checks passed
@llucax
llucax deleted the monotonic-timer branch November 6, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:synchronization Affects the synchronization of multiple sources (`select`, `merge`) part:tests Affects the unit, integration and performance (benchmarks) tests part:utilities Affects the utility receivers (`Timer`, `Event`, `FileWatcher`)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename Timer to MonotonicTimer

3 participants