summaryrefslogtreecommitdiff
path: root/kvmd/yamlconf
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/yamlconf
parent4b75221e9470b4a009955d7677f16adf8e23e302 (diff)
new typing style
Diffstat (limited to 'kvmd/yamlconf')
-rw-r--r--kvmd/yamlconf/__init__.py20
-rw-r--r--kvmd/yamlconf/loader.py8
2 files changed, 11 insertions, 17 deletions
diff --git a/kvmd/yamlconf/__init__.py b/kvmd/yamlconf/__init__.py
index d32e5fd3..faf8fa63 100644
--- a/kvmd/yamlconf/__init__.py
+++ b/kvmd/yamlconf/__init__.py
@@ -23,12 +23,8 @@
import contextlib
import json
-from typing import Tuple
-from typing import List
-from typing import Dict
from typing import Generator
from typing import Callable
-from typing import Optional
from typing import Any
@@ -38,8 +34,8 @@ class ConfigError(ValueError):
# =====
-def build_raw_from_options(options: List[str]) -> Dict[str, Any]:
- raw: Dict[str, Any] = {}
+def build_raw_from_options(options: list[str]) -> dict[str, Any]:
+ raw: dict[str, Any] = {}
for option in options:
(key, value) = (option.split("=", 1) + [None])[:2] # type: ignore
if len(key.strip()) == 0:
@@ -71,12 +67,12 @@ def _parse_value(value: str) -> Any:
class Section(dict):
def __init__(self) -> None:
dict.__init__(self)
- self.__meta: Dict[str, Dict[str, Any]] = {}
+ self.__meta: dict[str, dict[str, Any]] = {}
- def _unpack(self, ignore: Optional[List[str]]=None) -> Dict[str, Any]:
+ def _unpack(self, ignore: (list[str] | None)=None) -> dict[str, Any]:
if ignore is None:
ignore = []
- unpacked: Dict[str, Any] = {}
+ unpacked: dict[str, Any] = {}
for (key, value) in self.items():
if key not in ignore:
if isinstance(value, Section):
@@ -118,7 +114,7 @@ class Option:
def __init__(
self,
default: Any,
- type: Optional[Callable[[Any], Any]]=None, # pylint: disable=redefined-builtin
+ type: (Callable[[Any], Any] | None)=None, # pylint: disable=redefined-builtin
if_none: Any=Stub,
if_empty: Any=Stub,
only_if: str="",
@@ -150,13 +146,13 @@ def manual_validated(value: Any, *path: str) -> Generator[None, None, None]:
raise ConfigError(f"Invalid value {value!r} for key {'/'.join(path)!r}: {err}")
-def make_config(raw: Dict[str, Any], scheme: Dict[str, Any], _keys: Tuple[str, ...]=()) -> Section:
+def make_config(raw: dict[str, Any], scheme: dict[str, Any], _keys: tuple[str, ...]=()) -> Section:
if not isinstance(raw, dict):
raise ConfigError(f"The node {('/'.join(_keys) or '/')!r} must be a dictionary")
config = Section()
- def make_full_key(key: str) -> Tuple[str, ...]:
+ def make_full_key(key: str) -> tuple[str, ...]:
return _keys + (key,)
def make_full_name(key: str) -> str:
diff --git a/kvmd/yamlconf/loader.py b/kvmd/yamlconf/loader.py
index 682d5979..2dedc017 100644
--- a/kvmd/yamlconf/loader.py
+++ b/kvmd/yamlconf/loader.py
@@ -22,8 +22,6 @@
import os
-from typing import List
-from typing import Dict
from typing import IO
from typing import Any
@@ -52,7 +50,7 @@ class _YamlLoader(yaml.SafeLoader):
self.__root = os.path.dirname(yaml_file.name)
def include(self, node: yaml.nodes.Node) -> Any:
- incs: List[str]
+ incs: list[str]
if isinstance(node, yaml.nodes.SequenceNode):
incs = [
str(child)
@@ -63,8 +61,8 @@ class _YamlLoader(yaml.SafeLoader):
incs = [str(self.construct_scalar(node))] # type: ignore
return self.__inner_include(list(filter(None, incs)))
- def __inner_include(self, incs: List[str]) -> Any:
- tree: Dict = {}
+ def __inner_include(self, incs: list[str]) -> Any:
+ tree: dict = {}
for inc in filter(None, incs):
assert inc, inc
inc_path = os.path.join(self.__root, inc)