typing and refactoring on the way
diff --git a/wally/suits/io/fio.py b/wally/suits/io/fio.py
index 50bb1fd..2360a55 100644
--- a/wally/suits/io/fio.py
+++ b/wally/suits/io/fio.py
@@ -778,7 +778,7 @@
def prepare_data(cls, results) -> List[Dict[str, Any]]:
"""create a table with io performance report for console"""
- def key_func(data) -> Tuple(str, str, str, str, int):
+ def key_func(data: FioRunResult) -> Tuple[str, str, str, str, int]:
tpl = data.summary_tpl()
return (data.name,
tpl.oper,
diff --git a/wally/suits/io/fio_task_parser.py b/wally/suits/io/fio_task_parser.py
index 233f6e2..1b6ba21 100644
--- a/wally/suits/io/fio_task_parser.py
+++ b/wally/suits/io/fio_task_parser.py
@@ -7,7 +7,7 @@
import os.path
import argparse
import itertools
-from typing import Optional, Generator, Union, Dict, Iterable, Any, List, TypeVar, Callable
+from typing import Optional, Iterator, Union, Dict, Iterable, List, TypeVar, Callable, Tuple
from collections import OrderedDict, namedtuple
@@ -32,7 +32,7 @@
def copy(self) -> 'FioJobSection':
return copy.deepcopy(self)
- def required_vars(self) -> Generator[str, Var]:
+ def required_vars(self) -> Iterator[Tuple[str, Var]]:
for name, val in self.vals.items():
if isinstance(val, Var):
yield name, val
@@ -97,7 +97,7 @@
return val
-def fio_config_lexer(fio_cfg: str, fname: str) -> Generator[CfgLine]:
+def fio_config_lexer(fio_cfg: str, fname: str) -> Iterator[CfgLine]:
for lineno, oline in enumerate(fio_cfg.split("\n")):
try:
line = oline.strip()
@@ -130,7 +130,7 @@
raise ParseError(str(exc), fname, lineno, oline)
-def fio_config_parse(lexer_iter: Iterable[CfgLine]) -> Generator[FioJobSection]:
+def fio_config_parse(lexer_iter: Iterable[CfgLine]) -> Iterator[FioJobSection]:
in_globals = False
curr_section = None
glob_vals = OrderedDict()
@@ -204,7 +204,7 @@
yield curr_section
-def process_cycles(sec: FioJobSection) -> Generator[FioJobSection]:
+def process_cycles(sec: FioJobSection) -> Iterator[FioJobSection]:
cycles = OrderedDict()
for name, val in sec.vals.items():
@@ -277,7 +277,7 @@
MAGIC_OFFSET = 0.1885
-def finall_process(sec: FioJobSection, counter: Optional[List[int]] = [0]) -> FioJobSection:
+def finall_process(sec: FioJobSection, counter: List[int] = [0]) -> FioJobSection:
sec = sec.copy()
sec.vals['unified_rw_reporting'] = '1'
@@ -332,7 +332,7 @@
TestSumm = namedtuple("TestSumm", ("oper", "mode", "bsize", "iodepth", "vm_count"))
-def get_test_summary_tuple(sec: FioJobSection, vm_count=None) -> TestSumm:
+def get_test_summary_tuple(sec: FioJobSection, vm_count: int = None) -> TestSumm:
if isinstance(sec, dict):
vals = sec
else:
@@ -355,7 +355,7 @@
vm_count)
-def get_test_summary(sec: FioJobSection, vm_count: int=None, noqd: Optional[bool]=False) -> str:
+def get_test_summary(sec: FioJobSection, vm_count: int = None, noqd: bool = False) -> str:
tpl = get_test_summary_tuple(sec, vm_count)
res = "{0.oper}{0.mode}{0.bsize}".format(tpl)
@@ -372,7 +372,7 @@
return sec.vals.get('ramp_time', 0) + sec.vals.get('runtime', 0)
-def parse_all_in_1(source:str, fname: str=None) -> Generator[FioJobSection]:
+def parse_all_in_1(source:str, fname: str = None) -> Iterator[FioJobSection]:
return fio_config_parse(fio_config_lexer(source, fname))
@@ -381,13 +381,13 @@
def flatmap(func: Callable[[FM_FUNC_INPUT], Iterable[FM_FUNC_RES]],
- inp_iter: Iterable[FM_FUNC_INPUT]) -> Generator[FM_FUNC_RES]:
+ inp_iter: Iterable[FM_FUNC_INPUT]) -> Iterator[FM_FUNC_RES]:
for val in inp_iter:
for res in func(val):
yield res
-def fio_cfg_compile(source: str, fname: str, test_params: FIO_PARAMS) -> Generator[FioJobSection]:
+def fio_cfg_compile(source: str, fname: str, test_params: FIO_PARAMS) -> Iterator[FioJobSection]:
it = parse_all_in_1(source, fname)
it = (apply_params(sec, test_params) for sec in it)
it = flatmap(process_cycles, it)