fix: minor typing fix

This commit is contained in:
arabcoders 2026-01-19 17:15:10 +03:00
parent 57d582e265
commit c33827c6f7
4 changed files with 15 additions and 11 deletions

View file

@ -2,7 +2,7 @@ import asyncio
import datetime import datetime
import logging import logging
import uuid import uuid
from collections.abc import Awaitable from collections.abc import Callable
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Any from typing import Any
@ -198,10 +198,10 @@ class Event:
class EventListener: class EventListener:
def __init__(self, name: str, callback: callable): def __init__(self, name: str, callback: Callable[..., Any]):
self.name: str = name self.name: str = name
"The name of the listener." "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." "The callback function to call when the event is emitted."
self.is_coroutine: bool = asyncio.iscoroutinefunction(callback) self.is_coroutine: bool = asyncio.iscoroutinefunction(callback)
"Whether the callback is a coroutine function or not." "Whether the callback is a coroutine function or not."
@ -225,7 +225,7 @@ class EventBus(metaclass=Singleton):
self.debug: bool = False self.debug: bool = False
"Whether to log debug messages or not." "Whether to log debug messages or not."
self._offload: BackgroundWorker = None self._offload: BackgroundWorker | None = None
"The background worker to offload tasks to." "The background worker to offload tasks to."
@staticmethod @staticmethod
@ -239,7 +239,7 @@ class EventBus(metaclass=Singleton):
""" """
return EventBus() 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. Subscribe to an event.

View file

@ -19,7 +19,7 @@ class Scheduler(metaclass=Singleton):
self._jobs: dict[str, Cron] = {} self._jobs: dict[str, Cron] = {}
"The scheduled jobs." "The scheduled jobs."
self._loop = loop or asyncio.get_event_loop() self._loop: asyncio.AbstractEventLoop | None = loop
"The event loop to use." "The event loop to use."
@staticmethod @staticmethod
@ -114,6 +114,13 @@ class Scheduler(metaclass=Singleton):
if id and id in self._jobs: if id and id in self._jobs:
self.remove(id) 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 = Cron(spec=timer, func=func, args=args, kwargs=kwargs, uuid=id, start=True, loop=self._loop)
job_id = str(job.uuid) job_id = str(job.uuid)

View file

@ -1,7 +1,7 @@
import asyncio import asyncio
import logging import logging
import re import re
from typing import TYPE_CHECKING from typing import Any
from aiohttp import web from aiohttp import web
@ -13,9 +13,6 @@ from .Scheduler import Scheduler
from .Singleton import Singleton from .Singleton import Singleton
from .version import APP_VERSION from .version import APP_VERSION
if TYPE_CHECKING:
from app.library.dl_fields import Any
LOG: logging.Logger = logging.getLogger("update_checker") LOG: logging.Logger = logging.getLogger("update_checker")

View file

@ -39,7 +39,7 @@
import type { ModelRef } from 'vue'; import type { ModelRef } from 'vue';
import type { DLFieldType } from '~/types/dl_fields'; import type { DLFieldType } from '~/types/dl_fields';
defineProps<{ defineProps<{
id: string, id: number|string,
label: string, label: string,
field?: string, field?: string,
type: DLFieldType, type: DLFieldType,