summaryrefslogtreecommitdiff
path: root/kvmd/tools.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-09-04 18:08:40 +0300
committerMaxim Devaev <[email protected]>2022-09-04 18:08:40 +0300
commitee3e224e396494cd0d69bb6167087a071a20349c (patch)
tree5becd28570e58a03c6e1e231d0db24c264a73f88 /kvmd/tools.py
parent4b75221e9470b4a009955d7677f16adf8e23e302 (diff)
new typing style
Diffstat (limited to 'kvmd/tools.py')
-rw-r--r--kvmd/tools.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/kvmd/tools.py b/kvmd/tools.py
index 77a81d64..a21e085e 100644
--- a/kvmd/tools.py
+++ b/kvmd/tools.py
@@ -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