Skip to content

Commit ab6a421

Browse files
committed
Make _ActorInfo generic
When using an union, if we want to use a method present only in one of the union types, then we need to assert for the type, so it is better to just make it generic to the type is always the specific type. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent d40f9ca commit ab6a421

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/frequenz/sdk/microgrid/_data_pipeline.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@
5050
requests and will be able to keep up with higher request rates in larger installations.
5151
"""
5252

53+
_T = typing.TypeVar("_T")
54+
5355

5456
@dataclass
55-
class _ActorInfo:
57+
class _ActorInfo(typing.Generic[_T]):
5658
"""Holds instances of core data pipeline actors and their request channels."""
5759

58-
actor: "DataSourcingActor | ComponentMetricsResamplingActor"
60+
actor: _T
5961
channel: Broadcast["ComponentMetricRequest"]
6062

6163

@@ -82,8 +84,10 @@ def __init__(
8284

8385
self._channel_registry = ChannelRegistry(name="Data Pipeline Registry")
8486

85-
self._data_sourcing_actor: _ActorInfo | None = None
86-
self._resampling_actor: _ActorInfo | None = None
87+
self._data_sourcing_actor: _ActorInfo[DataSourcingActor] | None = None
88+
self._resampling_actor: _ActorInfo[
89+
ComponentMetricsResamplingActor
90+
] | None = None
8791

8892
self._battery_status_channel = Broadcast["BatteryStatus"](
8993
"battery-status", resend_latest=True

0 commit comments

Comments
 (0)