diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1bbbd075f..227441cb4 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -26,6 +26,8 @@ + The class is now immutable. + The constructor now accepts only keyword arguments. +- The Actor class now generates a name with the class name and the instance id. + ## New Features - `LoggingConfigUpdatingActor` diff --git a/src/frequenz/sdk/actor/_background_service.py b/src/frequenz/sdk/actor/_background_service.py index 2d44d2afe..9ca8e0184 100644 --- a/src/frequenz/sdk/actor/_background_service.py +++ b/src/frequenz/sdk/actor/_background_service.py @@ -73,10 +73,12 @@ def __init__(self, *, name: str | None = None) -> None: """Initialize this BackgroundService. Args: - name: The name of this background service. If `None`, `str(id(self))` will - be used. This is used mostly for debugging purposes. + name: The name of this background service. If `None`, id with the + class name will be generated. This is used mostly for debugging purposes. """ - self._name: str = str(id(self)) if name is None else name + self._name: str = ( + f"{self.__class__.__name__}_{id(self)}" if name is None else name + ) self._tasks: set[asyncio.Task[Any]] = set() @abc.abstractmethod diff --git a/tests/actor/test_background_service.py b/tests/actor/test_background_service.py index 5a8cc8e90..d1d941bf3 100644 --- a/tests/actor/test_background_service.py +++ b/tests/actor/test_background_service.py @@ -47,7 +47,7 @@ async def nop() -> None: async def test_construction_defaults() -> None: """Test the construction of a background service with default arguments.""" fake_service = FakeService() - assert fake_service.name == str(id(fake_service)) + assert fake_service.name.startswith("FakeService_") assert fake_service.tasks == set() assert fake_service.is_running is False assert str(fake_service) == f"FakeService[{fake_service.name}]"