Skip to content

Commit 519ae09

Browse files
authored
Deprecate DispatchInfo.components in favor of target (#194)
## Summary - Rename `DispatchInfo`'s `components` property to `target` in a backwards compatible way with deprecation warning - Update release notes to document the deprecation This change maintains backward compatibility by keeping the `components` property as a deprecated alias for `target`.
2 parents e45906b + bd5579e commit 519ae09

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## Upgrading
88

99
* The `key` parameter in the `Dispatcher` constructor is now deprecated. Use `auth_key` instead. The `sign_secret` parameter is an additional optional parameter for signing.
10+
* The `components` property in `DispatchInfo` is now deprecated. Use `target` instead.
1011

1112
## New Features
1213

src/frequenz/dispatch/_actor_dispatcher.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from frequenz.client.dispatch.types import DispatchId, TargetComponents
1616
from frequenz.core.id import BaseId
1717
from frequenz.sdk.actor import Actor, BackgroundService
18+
from typing_extensions import deprecated
1819

1920
from ._dispatch import Dispatch
2021

@@ -37,8 +38,18 @@ def __init__(self, dispatch_id: DispatchId | int) -> None:
3738
class DispatchInfo:
3839
"""Event emitted when the dispatch changes."""
3940

40-
components: TargetComponents
41-
"""Components to be used."""
41+
@property
42+
@deprecated("'components' is deprecated, use 'target' instead.")
43+
def components(self) -> TargetComponents:
44+
"""Get the target components.
45+
46+
Deprecation: Deprecated in v0.10.3
47+
Use [`target`][frequenz.dispatch.DispatchInfo.target] instead.
48+
"""
49+
return self.target
50+
51+
target: TargetComponents
52+
"""Target components to be used."""
4253

4354
dry_run: bool
4455
"""Whether this is a dry run."""
@@ -200,7 +211,7 @@ def start(self) -> None:
200211
async def _start_actor(self, dispatch: Dispatch) -> None:
201212
"""Start the actor the given dispatch refers to."""
202213
dispatch_update = DispatchInfo(
203-
components=dispatch.target,
214+
target=dispatch.target,
204215
dry_run=dispatch.dry_run,
205216
options=dispatch.payload,
206217
_src=dispatch,

tests/test_managing_actor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ async def test_simple_start_stop(
177177

178178
event = test_env.actor(1).initial_dispatch
179179
assert event.options == {"test": True}
180-
assert event.components == TargetIds(
181-
ComponentId(1), ComponentId(10), ComponentId(15)
182-
)
180+
assert event.target == TargetIds(ComponentId(1), ComponentId(10), ComponentId(15))
183181
assert event.dry_run is False
184182

185183
assert test_env.actor(1).is_running is True
@@ -309,7 +307,7 @@ async def test_dry_run(test_env: _TestEnv, fake_time: time_machine.Coordinates)
309307
event = test_env.actor(1).initial_dispatch
310308

311309
assert event.dry_run is dispatch.dry_run
312-
assert event.components == dispatch.target
310+
assert event.target == dispatch.target
313311
assert event.options == dispatch.payload
314312
assert test_env.actor(1).is_running is True
315313

0 commit comments

Comments
 (0)