From c33827c6f7ac4d696bed26a9fadfd5ea1e0ddea5 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Mon, 19 Jan 2026 17:15:10 +0300 Subject: [PATCH] fix: minor typing fix --- app/library/Events.py | 10 +++++----- app/library/Scheduler.py | 9 ++++++++- app/library/UpdateChecker.py | 5 +---- ui/app/components/DLInput.vue | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/library/Events.py b/app/library/Events.py index fae7f403..ff1b07b1 100644 --- a/app/library/Events.py +++ b/app/library/Events.py @@ -2,7 +2,7 @@ import asyncio import datetime import logging import uuid -from collections.abc import Awaitable +from collections.abc import Callable from dataclasses import dataclass, field from typing import Any @@ -198,10 +198,10 @@ class Event: class EventListener: - def __init__(self, name: str, callback: callable): + def __init__(self, name: str, callback: Callable[..., Any]): self.name: str = name "The name of the listener." - self.call_back: callable = callback + self.call_back: Callable[..., Any] = callback "The callback function to call when the event is emitted." self.is_coroutine: bool = asyncio.iscoroutinefunction(callback) "Whether the callback is a coroutine function or not." @@ -225,7 +225,7 @@ class EventBus(metaclass=Singleton): self.debug: bool = False "Whether to log debug messages or not." - self._offload: BackgroundWorker = None + self._offload: BackgroundWorker | None = None "The background worker to offload tasks to." @staticmethod @@ -239,7 +239,7 @@ class EventBus(metaclass=Singleton): """ return EventBus() - def subscribe(self, event: str | list | tuple, callback: Awaitable, name: str | None = None) -> "EventBus": + def subscribe(self, event: str | list | tuple, callback: Callable[..., Any], name: str | None = None) -> "EventBus": """ Subscribe to an event. diff --git a/app/library/Scheduler.py b/app/library/Scheduler.py index b3230454..adcf3dd6 100644 --- a/app/library/Scheduler.py +++ b/app/library/Scheduler.py @@ -19,7 +19,7 @@ class Scheduler(metaclass=Singleton): self._jobs: dict[str, Cron] = {} "The scheduled jobs." - self._loop = loop or asyncio.get_event_loop() + self._loop: asyncio.AbstractEventLoop | None = loop "The event loop to use." @staticmethod @@ -114,6 +114,13 @@ class Scheduler(metaclass=Singleton): if id and id in self._jobs: self.remove(id) + if not self._loop: + try: + self._loop = asyncio.get_running_loop() + except RuntimeError: + self._loop = asyncio.new_event_loop() + asyncio.set_event_loop(self._loop) + job = Cron(spec=timer, func=func, args=args, kwargs=kwargs, uuid=id, start=True, loop=self._loop) job_id = str(job.uuid) diff --git a/app/library/UpdateChecker.py b/app/library/UpdateChecker.py index 379eaf43..57c8e785 100644 --- a/app/library/UpdateChecker.py +++ b/app/library/UpdateChecker.py @@ -1,7 +1,7 @@ import asyncio import logging import re -from typing import TYPE_CHECKING +from typing import Any from aiohttp import web @@ -13,9 +13,6 @@ from .Scheduler import Scheduler from .Singleton import Singleton from .version import APP_VERSION -if TYPE_CHECKING: - from app.library.dl_fields import Any - LOG: logging.Logger = logging.getLogger("update_checker") diff --git a/ui/app/components/DLInput.vue b/ui/app/components/DLInput.vue index d927ef2a..a7faf30d 100644 --- a/ui/app/components/DLInput.vue +++ b/ui/app/components/DLInput.vue @@ -39,7 +39,7 @@ import type { ModelRef } from 'vue'; import type { DLFieldType } from '~/types/dl_fields'; defineProps<{ - id: string, + id: number|string, label: string, field?: string, type: DLFieldType,