Skip to content

Commit 63e1f85

Browse files
committed
Allow comparison with a plain Mapping
Since the comparison only compares the underlying `dict` and doesn't have into account the receiver, but just the current cache state, we can safely allow comparing to other `Mapping`s too. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent b59da99 commit 63e1f85

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/frequenz/channels/experimental/_grouping_latest_value_cache.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,13 @@ def __eq__(self, other: object, /) -> bool:
200200
Returns:
201201
`True` if the caches are equal, `False` otherwise.
202202
"""
203-
if not isinstance(other, GroupingLatestValueCache):
204-
return NotImplemented
205-
return self._latest_value_by_key == other._latest_value_by_key
203+
match other:
204+
case GroupingLatestValueCache():
205+
return self._latest_value_by_key == other._latest_value_by_key
206+
case Mapping():
207+
return self._latest_value_by_key == other
208+
case _:
209+
return NotImplemented
206210

207211
@override
208212
def __ne__(self, value: object, /) -> bool:

tests/test_grouping_latest_value_cache_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def test_latest_value_cache_key() -> None: # pylint: disable=too-many-sta
8888
assert cache.keys() == expected.keys()
8989
assert list(cache.values()) == list(expected.values())
9090
assert list(cache.items()) == list(expected.items())
91-
# assert cache == expected
91+
assert cache == expected
9292
assert list(cache) == list(expected)
9393

9494
cache.clear()

0 commit comments

Comments
 (0)