Skip to content

Commit 7a7c823

Browse files
authored
Improve documentation (#279)
This PR includes a lot of small documentation improvements and fixes, trying to make the documentation more consistent and easier to read. The commits are not particularly very well split, as many stuff was done in parallel and the splitting was done afterwards. Cleaning it up is very time demaning as it produces a lot of conflicts when rebasing.
2 parents 27f70c2 + f603b47 commit 7a7c823

File tree

13 files changed

+115
-194
lines changed

13 files changed

+115
-194
lines changed

docs/user-guide/receiving/synchronization/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ could be difficult to, for example, receive the first message of each receiver
55
as soon as it is available in one single task. A naive approach like this will
66
not work:
77

8-
```python
8+
```python show_lines="4:"
99
receiver1: Receiver[int] = channel1.new_receiver()
1010
receiver2: Receiver[int] = channel2.new_receiver()
1111

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ plugins:
119119
show_root_members_full_path: true
120120
show_signature_annotations: true
121121
show_source: true
122+
show_symbol_type_toc: true
122123
signature_crossrefs: true
123124
import:
124125
# See https://mkdocstrings.github.io/python/usage/#import for details

src/frequenz/channels/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
This package contains
77
[channel](https://en.wikipedia.org/wiki/Channel_(programming)) implementations.
88
9+
<!-- For the full documentation and user guide please visit the [project's
10+
website](https://frequenz-floss.github.io/frequenz-channels-python/) -->
11+
912
Base classes:
1013
1114
* [Receiver][frequenz.channels.Receiver]: An object that can wait for and

src/frequenz/channels/_anycast.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ async def main() -> None:
197197
"""
198198

199199
def __init__(self, *, name: str, limit: int = 10) -> None:
200-
"""Create an Anycast channel.
200+
"""Initialize this channel.
201201
202202
Args:
203203
name: The name of the channel. This is for logging purposes, and it will be
@@ -275,7 +275,6 @@ async def close(self) -> None:
275275
but after that, subsequent
276276
[receive()][frequenz.channels.Receiver.receive] calls will return `None`
277277
immediately.
278-
279278
"""
280279
self._closed = True
281280
async with self._send_cv:
@@ -284,19 +283,11 @@ async def close(self) -> None:
284283
self._recv_cv.notify_all()
285284

286285
def new_sender(self) -> Sender[_T]:
287-
"""Create a new sender.
288-
289-
Returns:
290-
A Sender instance attached to the Anycast channel.
291-
"""
286+
"""Return a new sender attached to this channel."""
292287
return _Sender(self)
293288

294289
def new_receiver(self) -> Receiver[_T]:
295-
"""Create a new receiver.
296-
297-
Returns:
298-
A Receiver instance attached to the Anycast channel.
299-
"""
290+
"""Return a new receiver attached to this channel."""
300291
return _Receiver(self)
301292

302293
def __str__(self) -> str:
@@ -319,7 +310,7 @@ class _Sender(Sender[_T]):
319310
"""
320311

321312
def __init__(self, chan: Anycast[_T]) -> None:
322-
"""Create a channel sender.
313+
"""Initialize this sender.
323314
324315
Args:
325316
chan: A reference to the channel that this sender belongs to.
@@ -339,7 +330,7 @@ async def send(self, msg: _T) -> None:
339330
msg: The message to be sent.
340331
341332
Raises:
342-
SenderError: if the underlying channel was closed.
333+
SenderError: If the underlying channel was closed.
343334
A [ChannelClosedError][frequenz.channels.ChannelClosedError] is
344335
set as the cause.
345336
"""
@@ -387,7 +378,7 @@ class _Receiver(Receiver[_T]):
387378
"""
388379

389380
def __init__(self, chan: Anycast[_T]) -> None:
390-
"""Create a channel receiver.
381+
"""Initialize this receiver.
391382
392383
Args:
393384
chan: A reference to the channel that this receiver belongs to.
@@ -431,8 +422,8 @@ def consume(self) -> _T:
431422
The next value that was received.
432423
433424
Raises:
434-
ReceiverStoppedError: if the receiver stopped producing messages.
435-
ReceiverError: if there is some problem with the receiver.
425+
ReceiverStoppedError: If the receiver stopped producing messages.
426+
ReceiverError: If there is some problem with the receiver.
436427
"""
437428
if ( # pylint: disable=protected-access
438429
self._next is _Empty and self._chan._closed

src/frequenz/channels/_broadcast.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async def main() -> None:
184184
"""
185185

186186
def __init__(self, *, name: str, resend_latest: bool = False) -> None:
187-
"""Create a Broadcast channel.
187+
"""Initialize this channel.
188188
189189
Args:
190190
name: The name of the channel. This is for logging purposes, and it will be
@@ -246,7 +246,7 @@ def is_closed(self) -> bool:
246246
return self._closed
247247

248248
async def close(self) -> None:
249-
"""Close the Broadcast channel.
249+
"""Close this channel.
250250
251251
Any further attempts to [send()][frequenz.channels.Sender.send] data
252252
will return `False`.
@@ -262,15 +262,11 @@ async def close(self) -> None:
262262
self._recv_cv.notify_all()
263263

264264
def new_sender(self) -> Sender[_T]:
265-
"""Create a new broadcast sender.
266-
267-
Returns:
268-
A Sender instance attached to the broadcast channel.
269-
"""
265+
"""Return a new sender attached to this channel."""
270266
return _Sender(self)
271267

272268
def new_receiver(self, *, name: str | None = None, limit: int = 50) -> Receiver[_T]:
273-
"""Create a new broadcast receiver.
269+
"""Return a new receiver attached to this channel.
274270
275271
Broadcast receivers have their own buffer, and when messages are not
276272
being consumed fast enough and the buffer fills up, old messages will
@@ -281,7 +277,7 @@ def new_receiver(self, *, name: str | None = None, limit: int = 50) -> Receiver[
281277
limit: Number of messages the receiver can hold in its buffer.
282278
283279
Returns:
284-
A Receiver instance attached to the broadcast channel.
280+
A new receiver attached to this channel.
285281
"""
286282
recv: _Receiver[_T] = _Receiver(name, limit, self)
287283
self._receivers[hash(recv)] = weakref.ref(recv)
@@ -290,7 +286,7 @@ def new_receiver(self, *, name: str | None = None, limit: int = 50) -> Receiver[
290286
return recv
291287

292288
def __str__(self) -> str:
293-
"""Return a string representation of this receiver."""
289+
"""Return a string representation of this channel."""
294290
return f"{type(self).__name__}:{self._name}"
295291

296292
def __repr__(self) -> str:
@@ -313,7 +309,7 @@ class _Sender(Sender[_T]):
313309
"""
314310

315311
def __init__(self, chan: Broadcast[_T]) -> None:
316-
"""Create a Broadcast sender.
312+
"""Initialize this sender.
317313
318314
Args:
319315
chan: A reference to the broadcast channel this sender belongs to.
@@ -328,7 +324,7 @@ async def send(self, msg: _T) -> None:
328324
msg: The message to be broadcast.
329325
330326
Raises:
331-
SenderError: if the underlying channel was closed.
327+
SenderError: If the underlying channel was closed.
332328
A [ChannelClosedError][frequenz.channels.ChannelClosedError] is
333329
set as the cause.
334330
"""
@@ -369,7 +365,7 @@ class _Receiver(Receiver[_T]):
369365
"""
370366

371367
def __init__(self, name: str | None, limit: int, chan: Broadcast[_T]) -> None:
372-
"""Create a broadcast receiver.
368+
"""Initialize this receiver.
373369
374370
Broadcast receivers have their own buffer, and when messages are not
375371
being consumed fast enough and the buffer fills up, old messages will
@@ -457,7 +453,7 @@ def consume(self) -> _T:
457453
The next value that was received.
458454
459455
Raises:
460-
ReceiverStoppedError: if there is some problem with the receiver.
456+
ReceiverStoppedError: If there is some problem with the receiver.
461457
"""
462458
if not self._q and self._chan._closed: # pylint: disable=protected-access
463459
raise ReceiverStoppedError(self) from ChannelClosedError(self._chan)

src/frequenz/channels/_exceptions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,45 @@
7070

7171

7272
class Error(RuntimeError):
73-
"""Base error.
73+
"""An error that originated in this library.
7474
75-
All exceptions generated by this library inherit from this exception.
75+
This is useful if you want to catch all exceptions generated by this library.
7676
"""
7777

7878
def __init__(self, message: str):
79-
"""Create a ChannelError instance.
79+
"""Initialize this error.
8080
8181
Args:
82-
message: An error message.
82+
message: The error message.
8383
"""
8484
super().__init__(message)
8585

8686

8787
class ChannelError(Error):
88-
"""An error produced in a channel.
88+
"""An error that originated in a channel.
8989
9090
All exceptions generated by channels inherit from this exception.
9191
"""
9292

9393
def __init__(self, message: str, channel: Any):
94-
"""Create a ChannelError instance.
94+
"""Initialize this error.
9595
9696
Args:
97-
message: An error message.
98-
channel: A reference to the channel that encountered the error.
97+
message: The error message.
98+
channel: The channel where the error happened.
9999
"""
100100
super().__init__(message)
101101
self.channel: Any = channel
102102
"""The channel where the error happened."""
103103

104104

105105
class ChannelClosedError(ChannelError):
106-
"""Error raised when trying to operate on a closed channel."""
106+
"""A closed channel was used."""
107107

108108
def __init__(self, channel: Any):
109-
"""Create a `ChannelClosedError` instance.
109+
"""Initialize this error.
110110
111111
Args:
112-
channel: A reference to the channel that was closed.
112+
channel: The channel that was closed.
113113
"""
114114
super().__init__(f"Channel {channel} was closed", channel)

src/frequenz/channels/_merge.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def merge(*receivers: Receiver[_T]) -> Merger[_T]:
8787
single stream.
8888
8989
Raises:
90-
ValueError: if no receivers are provided.
90+
ValueError: If no receivers are provided.
9191
"""
9292
if not receivers:
9393
raise ValueError("At least one receiver must be provided")
@@ -104,7 +104,7 @@ class Merger(Receiver[_T]):
104104
"""
105105

106106
def __init__(self, *receivers: Receiver[_T], name: str | None) -> None:
107-
"""Create a `Merger` instance.
107+
"""Initialize this merger.
108108
109109
Args:
110110
*receivers: The receivers to merge.
@@ -122,13 +122,13 @@ def __init__(self, *receivers: Receiver[_T], name: str | None) -> None:
122122
self._results: deque[_T] = deque(maxlen=len(self._receivers))
123123

124124
def __del__(self) -> None:
125-
"""Cleanup any pending tasks."""
125+
"""Finalize this merger."""
126126
for task in self._pending:
127127
if not task.done() and task.get_loop().is_running():
128128
task.cancel()
129129

130130
async def stop(self) -> None:
131-
"""Stop the `Merger` instance and cleanup any pending tasks."""
131+
"""Stop this merger."""
132132
for task in self._pending:
133133
task.cancel()
134134
await asyncio.gather(*self._pending, return_exceptions=True)
@@ -177,8 +177,8 @@ def consume(self) -> _T:
177177
The next value that was received.
178178
179179
Raises:
180-
ReceiverStoppedError: if the receiver stopped producing messages.
181-
ReceiverError: if there is some problem with the receiver.
180+
ReceiverStoppedError: If the receiver stopped producing messages.
181+
ReceiverError: If there is some problem with the receiver.
182182
"""
183183
if not self._results and not self._pending:
184184
raise ReceiverStoppedError(self)

0 commit comments

Comments
 (0)