diff --git a/statemachine/event.py b/statemachine/event.py index a82d9186..156980be 100644 --- a/statemachine/event.py +++ b/statemachine/event.py @@ -1,5 +1,6 @@ from inspect import isawaitable from typing import TYPE_CHECKING +from typing import Any from typing import List from uuid import uuid4 @@ -108,7 +109,7 @@ def __get__(self, instance, owner): return self return BoundEvent(id=self.id, name=self.name, _sm=instance) - def __call__(self, *args, **kwargs): + def __call__(self, *args, **kwargs) -> Any: """Send this event to the current state machine. Triggering an event on a state machine means invoking or sending a signal, initiating the diff --git a/statemachine/statemachine.py b/statemachine/statemachine.py index e5fe2628..4dc58c27 100644 --- a/statemachine/statemachine.py +++ b/statemachine/statemachine.py @@ -102,13 +102,13 @@ def _get_engine(self, rtc: bool): return SyncEngine(self, rtc=rtc) - def activate_initial_state(self): + def activate_initial_state(self) -> Any: result = self._engine.activate_initial_state() if not isawaitable(result): return result return run_async_from_sync(result) - def _processing_loop(self): + def _processing_loop(self) -> Any: return self._engine.processing_loop() def __init_subclass__(cls, strict_states: bool = False): @@ -298,7 +298,7 @@ def _put_nonblocking(self, trigger_data: TriggerData): """Put the trigger on the queue without blocking the caller.""" self._engine.put(trigger_data) - def send(self, event: str, *args, **kwargs): + def send(self, event: str, *args, **kwargs) -> Any: """Send an :ref:`Event` to the state machine. .. seealso:: diff --git a/statemachine/utils.py b/statemachine/utils.py index 0df178b3..cdd57175 100644 --- a/statemachine/utils.py +++ b/statemachine/utils.py @@ -1,5 +1,6 @@ import asyncio import threading +from typing import Any _cached_loop = threading.local() """Loop that will be used when the SM is running in a synchronous context. One loop per thread.""" @@ -25,7 +26,7 @@ def ensure_iterable(obj): return [obj] -def run_async_from_sync(coroutine): +def run_async_from_sync(coroutine: Any) -> Any: """ Compatibility layer to run an async coroutine from a synchronous context. """