Skip to content

Commit 617c1cb

Browse files
committed
Fix documentation and example
The module documentation of `GroupingLatestValueCache` wasn't updated to match the new `Mapping` interface. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 7c73438 commit 617c1cb

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/frequenz/channels/experimental/_grouping_latest_value_cache.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
stores the latest value received by that receiver for each key separately.
1212
1313
The `GroupingLatestValueCache` implements the [`Mapping`][collections.abc.Mapping]
14-
interface, so it can be used like a dictionary. In addition, it provides a
15-
[has_value][frequenz.channels.experimental.GroupingLatestValueCache.has_value] method to
16-
check if a value has been received for a specific key, and a
17-
[clear][frequenz.channels.experimental.GroupingLatestValueCache.clear] method to clear
18-
the cached value for a specific key.
14+
interface, so it can be used like a dictionary. It is not
15+
a [`MutableMapping`][collections.abc.MutableMapping] because users can't mutate the
16+
cache directly, it is only mutated by the underlying receiver. There is one exception
17+
though, users can clear individual keys from the cache using the
18+
[clear][frequenz.channels.experimental.GroupingLatestValueCache.clear] method.
1919
2020
Example:
2121
```python
@@ -27,12 +27,15 @@
2727
cache = GroupingLatestValueCache(channel.new_receiver(), key=lambda x: x[0])
2828
sender = channel.new_sender()
2929
30-
assert not cache.has_value(6)
30+
assert cache.get(6) is None
31+
assert 6 not in cache
3132
3233
await sender.send((6, "twenty-six"))
3334
34-
assert cache.has_value(6)
35+
assert 6 in cache
3536
assert cache.get(6) == (6, "twenty-six")
37+
38+
await cache.stop()
3639
```
3740
"""
3841

0 commit comments

Comments
 (0)