Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/frequenz/sdk/actor/_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import asyncio
import inspect
import logging
from typing import Any, Generic, Optional, Type, TypeVar
from typing import Any, Callable, Optional, Type, TypeVar

from typing_extensions import ParamSpec

from frequenz.sdk._internal._asyncio import cancel_and_await

_logger = logging.getLogger(__name__)

OT = TypeVar("OT")


def _check_run_method_exists(cls: Type[Any]) -> None:
"""Check if a run method exists in the given class.
Expand Down Expand Up @@ -57,7 +57,11 @@ class BaseActor:
restart_limit: Optional[int] = None


def actor(cls: Type[Any]) -> Type[Any]:
_P = ParamSpec("_P")
_R = TypeVar("_R")


def actor(cls: Callable[_P, _R]) -> Type[_R]:
"""Decorate a class into a simple composable actor.

A actor using the `actor` decorator should define an `async def run(self)`
Expand Down Expand Up @@ -180,10 +184,10 @@ async def run(self) -> None:

_check_run_method_exists(cls)

class ActorClass(cls, BaseActor, Generic[OT]): # type: ignore
class ActorClass(cls, BaseActor): # type: ignore
"""A wrapper class to make an actor."""

def __init__(self, *args: Any, **kwargs: Any) -> None:
def __init__(self, *args: _P.args, **kwargs: _P.kwargs) -> None:
"""Create an `ActorClass` instance.

Also call __init__ on `cls`.
Expand Down