Skip to content

Commit 3cf8d63

Browse files
committed
Support using BackgroundService as a *mixin*
This means using background service with multiple inheritance, so when calling `super().__init__()` it can properly ignore all the keyword arguments it doesn't use. This also means now `Actor` can be used as a *mixin*, as it doesn't provide its own `__init__()`. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 4a485d7 commit 3cf8d63

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/frequenz/sdk/actor/_background_service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,20 @@ async def main() -> None:
6969
```
7070
"""
7171

72-
def __init__(self, *, name: str | None = None) -> None:
72+
def __init__(self, *, name: str | None = None, **kwargs: Any) -> None:
7373
"""Initialize this BackgroundService.
7474
7575
Args:
7676
name: The name of this background service. If `None`, `str(id(self))` will
7777
be used. This is used mostly for debugging purposes.
78+
**kwargs: Additional keyword arguments to be passed to the parent class
79+
constructor. This is only provided to allow this class to be used as
80+
a mixin alonside other classes that require additional keyword
81+
arguments.
7882
"""
7983
self._name: str = str(id(self)) if name is None else name
8084
self._tasks: set[asyncio.Task[Any]] = set()
85+
super().__init__(**kwargs)
8186

8287
@abc.abstractmethod
8388
def start(self) -> None:

0 commit comments

Comments
 (0)