Skip to content

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented Jun 25, 2025

Fixes some documentation issues and brings the interface more close to MutableMapping.

llucax added 4 commits June 25, 2025 10:26
Signed-off-by: Leandro Lucarella <[email protected]>
The module documentation of `GroupingLatestValueCache` wasn't updated
to match the new `Mapping` interface.

Signed-off-by: Leandro Lucarella <[email protected]>
The module documentation is not being included in the rendered docs.
Normally this is done by including it in the User Guide, but since this
is an experimental module, we don't want to include it yet, so it is
easier to just move the docs to the class so they are rendered in the
API documentation.

Signed-off-by: Leandro Lucarella <[email protected]>
This follows the `dict` interface more closely, so it should be more
familiar to users.

Signed-off-by: Leandro Lucarella <[email protected]>
Copilot AI review requested due to automatic review settings June 25, 2025 11:34
@llucax llucax requested a review from a team as a code owner June 25, 2025 11:34
@llucax llucax requested a review from Marenz June 25, 2025 11:34
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:experimental Affects the experimental package labels Jun 25, 2025
@llucax llucax added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Jun 25, 2025
@llucax
Copy link
Contributor Author

llucax commented Jun 25, 2025

Not that I planned to do this, it just happened as I was adapting the code to do make receivers context managers...

@llucax llucax requested a review from shsms June 25, 2025 11:35
@llucax llucax self-assigned this Jun 25, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refines the GroupingLatestValueCache by updating its documentation, aligning its interface more closely with MutableMapping, and adding integration tests for new mapping methods.

  • Updated module and class docstrings for clarity and completeness
  • Implemented __getitem__, __delitem__, pop, popitem, and clear to mirror MutableMapping
  • Expanded integration tests to cover indexing, deletion, popping, iteration, and equality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/test_grouping_latest_value_cache_integration.py Added tests for __getitem__, __delitem__, pop, popitem, iteration, and equality
src/frequenz/channels/experimental/_grouping_latest_value_cache.py Revised module docstring, updated imports and overloads, implemented removal methods, refined __eq__/__ne__
Comments suppressed due to low confidence (2)

src/frequenz/channels/experimental/_grouping_latest_value_cache.py:4

  • [nitpick] The module docstring is very brief; consider adding a summary and a blank line followed by a longer description of the module’s purpose and contents per PEP 257.
"""The GroupingLatestValueCache caches the latest values in a receiver grouped by key."""

src/frequenz/channels/experimental/_grouping_latest_value_cache.py:33

  • This class implements mutating methods like pop, popitem, __delitem__, and clear, but only inherits from Mapping. Consider inheriting from MutableMapping to accurately reflect the supported interface.
class GroupingLatestValueCache(Mapping[HashableT, ValueT_co]):

llucax added 6 commits June 25, 2025 13:42
We can offer all item-clearing methods from `MutableMapping`, we just
don't want to allow users to update values.

Signed-off-by: Leandro Lucarella <[email protected]>
All other methods are just forwarding operations to the underlying
`dict`, so there is no point in handling `KeyError`s manually in this
method.

Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
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]>
Typing symbols are very fundamental and can make the code more readable
to use them directly.

Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax added this to the v1.10.0 milestone Jun 25, 2025
@llucax llucax enabled auto-merge June 25, 2025 12:26
Comment on lines +242 to +244
def pop(
self, key: HashableT, /, default: DefaultT | _NotSpecified = _NotSpecified()
) -> ValueT_co | DefaultT | None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def pop(
self, key: HashableT, /, default: DefaultT | _NotSpecified = _NotSpecified()
) -> ValueT_co | DefaultT | None:
def pop(
self, key: HashableT, /, default: DefaultT | None = None
) -> ValueT_co | DefaultT | None:

Then you can use return self._latest_value_by_key.pop(key, default) as the only body, because that's the exact signature of dict.pop(), and no need for special cases.

And if a user wants to have None in ValueT_co, they can make their own sentinel that will be DefaultT. So we don't need to make a sentinel to be able to satisfy MutableMapping.

Copy link
Contributor Author

@llucax llucax Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the problem is pop() raises when the default is not specified, it doesn't return None (is not symmetric with get()), so we need to be able to tell between not passing the argument and passing None.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh damn, that's such a bad API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

shsms
shsms previously approved these changes Jul 1, 2025
@llucax llucax added this pull request to the merge queue Jul 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 1, 2025
@llucax llucax added this pull request to the merge queue Jul 2, 2025
@llucax llucax removed this pull request from the merge queue due to a manual request Jul 2, 2025
@llucax
Copy link
Contributor Author

llucax commented Jul 2, 2025

Mmm, failing in Python 3.12, will have to have a look.

Importing those symbols from `typing` is deprecated.

Signed-off-by: Leandro Lucarella <[email protected]>
@llucax
Copy link
Contributor Author

llucax commented Jul 2, 2025

************* Module frequenz.channels.experimental._grouping_latest_value_cache
src/frequenz/channels/experimental/_grouping_latest_value_cache.py:9:0: W4904: Using deprecated class Hashable of module typing (deprecated-class)

Strange that it only fails in 3.12.

Updated with a new commit with a fix.

@llucax llucax enabled auto-merge July 2, 2025 08:41
@llucax llucax requested a review from shsms July 2, 2025 08:41
@llucax llucax added this pull request to the merge queue Jul 2, 2025
Merged via the queue into frequenz-floss:v1.x.x with commit 55ac012 Jul 2, 2025
5 checks passed
@llucax llucax deleted the grouping branch July 2, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmd:skip-release-notes It is not necessary to update release notes for this PR part:experimental Affects the experimental package part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants