Skip to content
Snippets Groups Projects
Commit 49bc28c5 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Change MethodT

parent 7268bf6e
Branches
Tags
1 merge request!1First try of type hints
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment