Skip to content

Commit 9cd9516

Browse files
authored
Improve documentation (#136)
- Add missing enum members documentation - Make cross-linking more consistent - Improve Timer documentation
2 parents ce33e66 + af1689f commit 9cd9516

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

src/frequenz/channels/util/_file_watcher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ class EventType(Enum):
2525
"""Available types of changes to watch for."""
2626

2727
CREATE = Change.added
28+
"""A new file was created."""
29+
2830
MODIFY = Change.modified
31+
"""An existing file was modified."""
32+
2933
DELETE = Change.deleted
34+
"""An existing file was deleted."""
3035

3136
@dataclass(frozen=True)
3237
class Event:

src/frequenz/channels/util/_select.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
class Selected(Generic[_T]):
21-
"""A result of a [`select`][frequenz.channels.util.select] iteration.
21+
"""A result of a [`select()`][frequenz.channels.util.select] iteration.
2222
2323
The selected receiver is consumed immediately and the received value is stored in
2424
the instance, unless there was an exception while receiving the value, in which case
@@ -28,7 +28,7 @@ class Selected(Generic[_T]):
2828
[`selected_from()`][frequenz.channels.util.selected_from] function to determine
2929
which receiver was selected.
3030
31-
Please see [`select`][frequenz.channels.util.select] for an example.
31+
Please see [`select()`][frequenz.channels.util.select] for an example.
3232
"""
3333

3434
class _EmptyResult:
@@ -141,7 +141,7 @@ def __repr__(self) -> str:
141141
def selected_from(
142142
selected: Selected[Any], receiver: Receiver[_T]
143143
) -> TypeGuard[Selected[_T]]:
144-
"""Check if the given receiver was selected by [`select`][frequenz.channels.util.select].
144+
"""Check if the given receiver was selected by [`select()`][frequenz.channels.util.select].
145145
146146
This function is used in conjunction with the
147147
[`Selected`][frequenz.channels.util.Selected] class to determine which receiver was
@@ -150,7 +150,7 @@ def selected_from(
150150
It also works as a [type guard][typing.TypeGuard] to narrow the type of the
151151
`Selected` instance to the type of the receiver.
152152
153-
Please see [`select`][frequenz.channels.util.select] for an example.
153+
Please see [`select()`][frequenz.channels.util.select] for an example.
154154
155155
Args:
156156
selected: The result of a `select()` iteration.
@@ -165,7 +165,7 @@ def selected_from(
165165

166166

167167
class SelectError(BaseException):
168-
"""A base exception for [`select`][frequenz.channels.util.select].
168+
"""A base exception for [`select()`][frequenz.channels.util.select].
169169
170170
This exception is raised when a `select()` iteration fails. It is raised as
171171
a single exception when one receiver fails during normal operation (while calling
@@ -196,7 +196,7 @@ def __init__(self, selected: Selected[_T]) -> None:
196196
class SelectErrorGroup(BaseExceptionGroup[BaseException], SelectError):
197197
"""An exception group for [`select()`][frequenz.channels.util.select] operation.
198198
199-
This exception group is raised when a [`select()`] loops fails while cleaning up
199+
This exception group is raised when a `select()` loops fails while cleaning up
200200
runing tasts to check for ready receivers.
201201
"""
202202

src/frequenz/channels/util/_timer.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,36 +270,49 @@ def __repr__(self) -> str:
270270
class Timer(Receiver[timedelta]):
271271
"""A timer receiver that triggers every `interval` time.
272272
273-
The timer as microseconds resolution, so the `interval` must be at least
273+
The timer has microseconds resolution, so the
274+
[`interval`][frequenz.channels.util.Timer.interval] must be at least
274275
1 microsecond.
275276
276-
The message it produces is a `timedelta` containing the drift of the timer,
277-
i.e. the difference between when the timer should have triggered and the time
278-
when it actually triggered.
277+
The message it produces is a [`timedelta`][datetime.timedelta] containing the drift
278+
of the timer, i.e. the difference between when the timer should have triggered and
279+
the time when it actually triggered.
279280
280281
This drift will likely never be `0`, because if there is a task that is
281282
running when it should trigger, the timer will be delayed. In this case the
282283
drift will be positive. A negative drift should be technically impossible,
283-
as the timer uses `asyncio`s loop monotonic clock.
284+
as the timer uses [`asyncio`][asyncio]s loop monotonic clock.
284285
285-
If the timer is delayed too much, then the timer will behave according to
286-
the `missed_tick_policy`. Missing ticks might or might not trigger
287-
a message and the drift could be accumulated or not depending on the
288-
chosen policy.
286+
If the timer is delayed too much, then it will behave according to the
287+
[`missed_tick_policy`][frequenz.channels.util.Timer.missed_tick_policy]. Missing
288+
ticks might or might not trigger a message and the drift could be accumulated or not
289+
depending on the chosen policy.
289290
290-
The timer accepts an optional `loop`, which will be used to track the time.
291-
If `loop` is `None`, then the running loop will be used (if there is no
292-
running loop most calls will raise a `RuntimeError`).
291+
These are the currently built-in available policies:
293292
294-
Starting the timer can be delayed if necessary by using `auto_start=False`
295-
(for example until we have a running loop). A call to `reset()`, `ready()`,
296-
`receive()` or the async iterator interface to await for a new message will
297-
start the timer.
293+
* [`SkipMissedAndDrift`][frequenz.channels.util.SkipMissedAndDrift]
294+
* [`SkipMissedAndResync`][frequenz.channels.util.SkipMissedAndResync]
295+
* [`TriggerAllMissed`][frequenz.channels.util.TriggerAllMissed]
298296
299297
For the most common cases, a specialized constructor is provided:
300298
301-
* [`periodic()`][frequenz.channels.util.Timer.periodic]
302-
* [`timeout()`][frequenz.channels.util.Timer.timeout]
299+
* [`periodic()`][frequenz.channels.util.Timer.periodic] (uses the
300+
[`TriggerAllMissed`][frequenz.channels.util.TriggerAllMissed] or
301+
[`SkipMissedAndResync`][frequenz.channels.util.SkipMissedAndResync] policy)
302+
* [`timeout()`][frequenz.channels.util.Timer.timeout] (uses the
303+
[`SkipMissedAndDrift`][frequenz.channels.util.SkipMissedAndDrift] policy)
304+
305+
The timer accepts an optional [`loop`][frequenz.channels.util.Timer.loop], which
306+
will be used to track the time. If `loop` is `None`, then the running loop will be
307+
used (if there is no running loop most calls will raise
308+
a [`RuntimeError`][RuntimeError]).
309+
310+
Starting the timer can be delayed if necessary by using `auto_start=False`
311+
(for example until we have a running loop). A call to
312+
[`reset()`][frequenz.channels.util.Timer.reset],
313+
[`ready()`][frequenz.channels.util.Timer.ready],
314+
[`receive()`][frequenz.channels.util.Timer.receive] or the async iterator interface
315+
to await for a new message will start the timer.
303316
304317
Example: Periodic timer example
305318
```python

0 commit comments

Comments
 (0)