mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
new typing style
This commit is contained in:
@@ -26,9 +26,6 @@ import multiprocessing.queues
|
||||
import queue
|
||||
import shlex
|
||||
|
||||
from typing import Tuple
|
||||
from typing import List
|
||||
from typing import Dict
|
||||
from typing import Hashable
|
||||
from typing import TypeVar
|
||||
|
||||
@@ -39,7 +36,7 @@ def remap(value: int, in_min: int, in_max: int, out_min: int, out_max: int) -> i
|
||||
|
||||
|
||||
# =====
|
||||
def cmdfmt(cmd: List[str]) -> str:
|
||||
def cmdfmt(cmd: list[str]) -> str:
|
||||
return " ".join(map(shlex.quote, cmd))
|
||||
|
||||
|
||||
@@ -48,7 +45,7 @@ def efmt(err: Exception) -> str:
|
||||
|
||||
|
||||
# =====
|
||||
def merge(dest: Dict, src: Dict) -> None:
|
||||
def merge(dest: dict, src: dict) -> None:
|
||||
for key in src:
|
||||
if key in dest:
|
||||
if isinstance(dest[key], dict) and isinstance(src[key], dict):
|
||||
@@ -57,7 +54,7 @@ def merge(dest: Dict, src: Dict) -> None:
|
||||
dest[key] = src[key]
|
||||
|
||||
|
||||
def rget(dct: Dict, *keys: Hashable) -> Dict:
|
||||
def rget(dct: dict, *keys: Hashable) -> dict:
|
||||
result = functools.reduce((lambda nxt, key: nxt.get(key, {})), keys, dct)
|
||||
if not isinstance(result, dict):
|
||||
raise TypeError(f"Not a dict as result: {result!r} from {dct!r} at {list(keys)}")
|
||||
@@ -68,11 +65,11 @@ _DictKeyT = TypeVar("_DictKeyT")
|
||||
_DictValueT = TypeVar("_DictValueT")
|
||||
|
||||
|
||||
def sorted_kvs(dct: Dict[_DictKeyT, _DictValueT]) -> List[Tuple[_DictKeyT, _DictValueT]]:
|
||||
def sorted_kvs(dct: dict[_DictKeyT, _DictValueT]) -> list[tuple[_DictKeyT, _DictValueT]]:
|
||||
return sorted(dct.items(), key=operator.itemgetter(0))
|
||||
|
||||
|
||||
def swapped_kvs(dct: Dict[_DictKeyT, _DictValueT]) -> Dict[_DictValueT, _DictKeyT]:
|
||||
def swapped_kvs(dct: dict[_DictKeyT, _DictValueT]) -> dict[_DictValueT, _DictKeyT]:
|
||||
return {value: key for (key, value) in dct.items()}
|
||||
|
||||
|
||||
@@ -86,7 +83,7 @@ def clear_queue(q: multiprocessing.queues.Queue) -> None: # pylint: disable=inv
|
||||
|
||||
|
||||
# =====
|
||||
def build_cmd(cmd: List[str], cmd_remove: List[str], cmd_append: List[str]) -> List[str]:
|
||||
def build_cmd(cmd: list[str], cmd_remove: list[str], cmd_append: list[str]) -> list[str]:
|
||||
assert len(cmd) >= 1, cmd
|
||||
return [
|
||||
cmd[0], # Executable
|
||||
|
||||
Reference in New Issue
Block a user