From a829da2789b38ae0c3ed2e87022a8cdd062e28f0 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Fri, 16 Feb 2024 16:41:49 -0500 Subject: [PATCH] Refactor event handling in EventHandler class --- pyflowlauncher/event.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyflowlauncher/event.py b/pyflowlauncher/event.py index ebdf518..3db6360 100644 --- a/pyflowlauncher/event.py +++ b/pyflowlauncher/event.py @@ -23,8 +23,8 @@ def add_events(self, events: Iterable[Callable[..., Any]]): def add_exception_handler(self, exception: Type[Exception], handler: Callable[..., Any]): self._handlers[exception] = handler - def _call_event(self, event: str, *args, **kwargs) -> Callable[..., Any] | None: - return self._events[event](*args, **kwargs) + def get_event(self, event: str) -> Callable[..., Any]: + return self._events[event] async def _await_maybe(self, result: Any) -> Any: if asyncio.iscoroutine(result): @@ -33,7 +33,7 @@ async def _await_maybe(self, result: Any) -> Any: async def trigger_event(self, event: str, *args, **kwargs) -> Any: try: - result = self._call_event(event, *args, **kwargs) + result = self.get_event(event)(*args, **kwargs) return await self._await_maybe(result) except Exception as e: handler = self._handlers.get(type(e), None)