mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
typing fixes
This commit is contained in:
parent
51ac65d542
commit
c6524fc7ac
@ -21,7 +21,6 @@
|
||||
|
||||
|
||||
import asyncio
|
||||
import asyncio.queues
|
||||
import threading
|
||||
import dataclasses
|
||||
|
||||
@ -147,7 +146,7 @@ class _DebouncedValue:
|
||||
self.__notifier = notifier
|
||||
self.__loop = loop
|
||||
|
||||
self.__queue: asyncio.queues.Queue = asyncio.Queue(loop=loop)
|
||||
self.__queue: "asyncio.Queue[bool]" = asyncio.Queue(loop=loop)
|
||||
self.__task = loop.create_task(self.__consumer_task_loop())
|
||||
|
||||
def set(self, value: bool) -> None:
|
||||
|
||||
@ -21,8 +21,6 @@
|
||||
|
||||
|
||||
import multiprocessing
|
||||
import multiprocessing.queues
|
||||
import multiprocessing.sharedctypes
|
||||
import queue
|
||||
|
||||
from typing import Dict
|
||||
@ -33,7 +31,7 @@ from . import aiotools
|
||||
# =====
|
||||
class AioProcessNotifier:
|
||||
def __init__(self) -> None:
|
||||
self.__queue: multiprocessing.queues.Queue = multiprocessing.Queue()
|
||||
self.__queue: "multiprocessing.Queue[None]" = multiprocessing.Queue()
|
||||
|
||||
def notify(self) -> None:
|
||||
self.__queue.put_nowait(None)
|
||||
@ -62,7 +60,7 @@ class AioSharedFlags:
|
||||
|
||||
self.__notifier = notifier
|
||||
|
||||
self.__flags: Dict[str, multiprocessing.sharedctypes.RawValue] = {
|
||||
self.__flags = {
|
||||
key: multiprocessing.RawValue("i", int(value)) # type: ignore
|
||||
for (key, value) in initial.items()
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
|
||||
|
||||
import asyncio
|
||||
import asyncio.queues
|
||||
import functools
|
||||
import types
|
||||
|
||||
@ -92,7 +91,7 @@ async def wait_first(*aws: Awaitable) -> Tuple[Set[asyncio.Future], Set[asyncio.
|
||||
# =====
|
||||
class AioNotifier:
|
||||
def __init__(self) -> None:
|
||||
self.__queue: asyncio.queues.Queue = asyncio.Queue()
|
||||
self.__queue: "asyncio.Queue[None]" = asyncio.Queue()
|
||||
|
||||
async def notify(self) -> None:
|
||||
await self.__queue.put(None)
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
|
||||
|
||||
import asyncio
|
||||
import asyncio.queues
|
||||
import contextlib
|
||||
import json
|
||||
import types
|
||||
@ -133,7 +132,7 @@ class KvmdClientWs:
|
||||
def __init__(self, ws: aiohttp.ClientWebSocketResponse) -> None:
|
||||
self.__ws = ws
|
||||
|
||||
self.__writer_queue: asyncio.queues.Queue = asyncio.Queue()
|
||||
self.__writer_queue: "asyncio.Queue[Dict]" = asyncio.Queue()
|
||||
self.__communicated = False
|
||||
|
||||
async def communicate(self) -> AsyncGenerator[Dict, None]:
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
import sys
|
||||
import os
|
||||
import asyncio
|
||||
import asyncio.queues
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
import struct
|
||||
@ -230,7 +229,7 @@ class Inotify:
|
||||
|
||||
self.__moved: Dict[int, str] = {}
|
||||
|
||||
self.__events_queue: asyncio.queues.Queue = asyncio.Queue()
|
||||
self.__events_queue: "asyncio.Queue[InotifyEvent]" = asyncio.Queue()
|
||||
|
||||
def watch(self, path: str, mask: int) -> None:
|
||||
path = os.path.normpath(path)
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
import os
|
||||
import select
|
||||
import multiprocessing
|
||||
import multiprocessing.queues
|
||||
import queue
|
||||
import errno
|
||||
import time
|
||||
@ -76,7 +75,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
|
||||
self.__noop = noop
|
||||
|
||||
self.__fd = -1
|
||||
self.__events_queue: multiprocessing.queues.Queue = multiprocessing.Queue()
|
||||
self.__events_queue: "multiprocessing.Queue[BaseEvent]" = multiprocessing.Queue()
|
||||
self.__state_flags = aiomulti.AioSharedFlags({"online": True, **initial_state}, notifier)
|
||||
self.__stop_event = multiprocessing.Event()
|
||||
|
||||
@ -93,7 +92,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
|
||||
if self.__ensure_device(): # Check device and process reports if needed
|
||||
self.__read_all_reports()
|
||||
try:
|
||||
event: BaseEvent = self.__events_queue.get(timeout=0.1)
|
||||
event = self.__events_queue.get(timeout=0.1)
|
||||
except queue.Empty:
|
||||
if not self.__udc.can_operate():
|
||||
self.__close_device()
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
|
||||
import os
|
||||
import multiprocessing
|
||||
import multiprocessing.queues
|
||||
import dataclasses
|
||||
import queue
|
||||
import struct
|
||||
@ -225,7 +224,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
|
||||
self.__gpio = _Gpio(reset_pin, reset_delay)
|
||||
|
||||
self.__events_queue: multiprocessing.queues.Queue = multiprocessing.Queue()
|
||||
self.__events_queue: "multiprocessing.Queue[_BaseEvent]" = multiprocessing.Queue()
|
||||
|
||||
self.__notifier = aiomulti.AioProcessNotifier()
|
||||
self.__state_flags = aiomulti.AioSharedFlags({
|
||||
@ -344,7 +343,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
with self.__get_serial() as tty:
|
||||
while not (self.__stop_event.is_set() and self.__events_queue.qsize() == 0):
|
||||
try:
|
||||
event: _BaseEvent = self.__events_queue.get(timeout=0.1)
|
||||
event = self.__events_queue.get(timeout=0.1)
|
||||
except queue.Empty:
|
||||
self.__process_command(tty, b"\x01\x00\x00\x00\x00") # Ping
|
||||
else:
|
||||
|
||||
@ -22,9 +22,10 @@
|
||||
|
||||
import os
|
||||
import multiprocessing
|
||||
import multiprocessing.queues
|
||||
import time
|
||||
|
||||
from typing import Literal
|
||||
|
||||
import setproctitle
|
||||
|
||||
from kvmd.apps.cleanup import main
|
||||
@ -32,7 +33,8 @@ from kvmd.apps.cleanup import main
|
||||
|
||||
# =====
|
||||
def test_ok(tmpdir) -> None: # type: ignore
|
||||
queue: multiprocessing.queues.Queue = multiprocessing.Queue()
|
||||
_ = Literal # Makes liters happy
|
||||
queue: "multiprocessing.Queue[Literal[True]]" = multiprocessing.Queue()
|
||||
|
||||
ustreamer_sock_path = os.path.abspath(str(tmpdir.join("ustreamer-fake.sock")))
|
||||
open(ustreamer_sock_path, "w").close()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user