diff --git a/libs/lib/xaal/lib/devices.py b/libs/lib/xaal/lib/devices.py index e4c395394ad9335ccf81dce59560765bb91816e9..18e7f84c0f040453941198f8cdadb2e8b1fd17a3 100644 --- a/libs/lib/xaal/lib/devices.py +++ b/libs/lib/xaal/lib/devices.py @@ -33,12 +33,9 @@ if typing.TYPE_CHECKING: from .engine import Engine from .core import EngineMixin -# Funtion type with any arguments and return a dict or None (device methods) -MethodT = TypeVar( - "MethodT", - Callable[..., Union[dict, None]], - Callable[..., Awaitable[Union[dict, None]]] -) +# Funtion types with any arguments and return a dict or None (device methods) +SyncMethodT = Callable[..., Union[dict, None]] # Fonction synchrone qui retourne un dict ou None +AsyncMethodT = Callable[..., Awaitable[Union[dict, None]]] # Coroutine qui retourne un dict ou None logger = logging.getLogger(__name__) @@ -137,7 +134,7 @@ class Device(object): self.next_alive = 0 # Default attributes & methods self.__attributes = Attributes() - self.methods = { + self.methods: dict[str, Union[SyncMethodT, AsyncMethodT]] = { 'get_attributes': self._get_attributes, 'get_description': self._get_description, } @@ -222,14 +219,14 @@ class Device(object): else: raise DeviceError("Invalid attributes list, use class Attributes)") - def add_method(self, name: str, func: MethodT): + def add_method(self, name: str, func: Union[SyncMethodT, AsyncMethodT]): self.methods.update({name: func}) def del_method(self, name: str): if name in self.methods: del self.methods[name] - def get_methods(self) -> dict: + def get_methods(self) -> dict[str, Union[SyncMethodT, AsyncMethodT]]: return self.methods def update_alive(self):