Skip to content

Commit 6b67fe1

Browse files
committed
Assert Receiver.ready() is called before calls to consume()
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent c13edc3 commit 6b67fe1

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

src/frequenz/channels/anycast.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,9 @@ def consume(self) -> T:
192192
Returns:
193193
The next value that was received.
194194
"""
195-
if self._next is None:
196-
raise EOFError(
197-
"`consume()` was called before a call to `ready()` finished."
198-
)
195+
assert (
196+
self._next is not None
197+
), "calls to `consume()` must be follow a call to `ready()`"
199198
next_val = self._next
200199
self._next = None
201200
return next_val

src/frequenz/channels/broadcast.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def consume(self) -> T:
275275
Returns:
276276
The next value that was received.
277277
"""
278+
assert self._q, "calls to `consume()` must be follow a call to `ready()`"
278279
ret = self._q.popleft()
279280
return ret
280281

src/frequenz/channels/merge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def consume(self) -> T:
8383
Returns:
8484
The next value that was received.
8585
"""
86-
if not self._results:
87-
raise EOFError("`consume` called before `ready` finished.")
86+
assert self._results, "calls to `consume()` must be follow a call to `ready()`"
8887

8988
return self._results.popleft()

src/frequenz/channels/merge_named.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def consume(self) -> Tuple[str, T]:
7070
Returns:
7171
The next value that was received, along with its name.
7272
"""
73-
if not self._results:
74-
raise EOFError("_get called before _ready finished.")
73+
assert self._results, "calls to `consume()` must be follow a call to `ready()`"
7574

7675
return self._results.popleft()

src/frequenz/channels/utils/file_watcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def consume(self) -> pathlib.Path:
8888
Returns:
8989
The next change that was received.
9090
"""
91+
assert self._changes, "calls to `consume()` must be follow a call to `ready()`"
9192
change = self._changes.pop()
9293
# Tuple of (Change, path) returned by watchfiles
9394
if change is None or len(change) != 2:

src/frequenz/channels/utils/timer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ def consume(self) -> datetime:
118118
* **v0.11.0:** Returns a timezone-aware datetime with UTC timezone
119119
instead of a native datetime object.
120120
"""
121-
if self._now is None:
122-
raise EOFError("`consume` called before `ready` finished")
121+
assert (
122+
self._now is not None
123+
), "calls to `consume()` must be follow a call to `ready()`"
123124
now = self._now
124125
self._now = None
125126
return now

0 commit comments

Comments
 (0)