Skip to content

Commit 983a5e4

Browse files
Update sender type in ConfigManagingActor (#1010)
The ConfigManagingActor now sends a `collections.abc.Mapping` type as the output sender type to indicate to the user that the broadcasted configuration is intended to be read-only. This change leverages type checkers (e.g., mypy, etc.) to help ensure that users do not attempt to modify the dictionary contents. Note that this change won't prevent users from modifying the contents at runtime, but it will help prevent accidental modifications.
2 parents 8d2002f + fee07e3 commit 983a5e4

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
- Power distribution results are no longer available through the `power_status` streams in the `*Pool`s. They can now be accessed as a stream from a separate property `power_distribution_results`, which is available from all the `*Pool`s.
2323

24+
- The `ConfigManagingActor` now uses `collections.abc.Mapping` as the output sender type. This change indicates that the broadcasted configuration is intended to be read-only.
25+
2426
## New Features
2527

2628
- Classes `Bounds` and `SystemBounds` now implement the `__contains__` method, allowing the use of the `in` operator to check whether a value falls within the bounds or not.

src/frequenz/sdk/actor/_config_managing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ConfigManagingActor(Actor):
3232
def __init__(
3333
self,
3434
config_path: pathlib.Path | str,
35-
output: Sender[dict[str, Any]],
35+
output: Sender[abc.Mapping[str, Any]],
3636
event_types: abc.Set[EventType] = frozenset(EventType),
3737
*,
3838
name: str | None = None,
@@ -58,9 +58,9 @@ def __init__(
5858
self._file_watcher: FileWatcher = FileWatcher(
5959
paths=[self._config_path.parent], event_types=event_types
6060
)
61-
self._output: Sender[dict[str, Any]] = output
61+
self._output: Sender[abc.Mapping[str, Any]] = output
6262

63-
def _read_config(self) -> dict[str, Any]:
63+
def _read_config(self) -> abc.Mapping[str, Any]:
6464
"""Read the contents of the configuration file.
6565
6666
Returns:

tests/actor/test_config_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""Test for ConfigManager."""
55
import os
66
import pathlib
7+
from collections.abc import Mapping
78
from typing import Any
89

910
import pytest
@@ -65,7 +66,7 @@ async def test_update(self, config_file: pathlib.Path) -> None:
6566
- the initial content of the content file is correct
6667
- the config file modifications are picked up and the new content is correct
6768
"""
68-
config_channel: Broadcast[dict[str, Any]] = Broadcast(
69+
config_channel: Broadcast[Mapping[str, Any]] = Broadcast(
6970
name="Config Channel", resend_latest=True
7071
)
7172
config_receiver = config_channel.new_receiver()
@@ -91,7 +92,7 @@ async def test_update(self, config_file: pathlib.Path) -> None:
9192

9293
async def test_update_relative_path(self, config_file: pathlib.Path) -> None:
9394
"""Test ConfigManagingActor with a relative path."""
94-
config_channel: Broadcast[dict[str, Any]] = Broadcast(
95+
config_channel: Broadcast[Mapping[str, Any]] = Broadcast(
9596
name="Config Channel", resend_latest=True
9697
)
9798
config_receiver = config_channel.new_receiver()

0 commit comments

Comments
 (0)