Add more precise typing for checklist: List[ChecklistObjType]
[kconfig-hardened-check.git] / kernel_hardening_checker / __init__.py
index 3a30aefca388f48ee5e31343fbeab0d76e67fbef..ca163b7db5a077d0895faf4baa6f161f5b16e9bd 100644 (file)
@@ -19,7 +19,7 @@ import re
 import json
 from .__about__ import __version__
 from .checks import add_kconfig_checks, add_cmdline_checks, normalize_cmdline_options, add_sysctl_checks
-from .engine import StrOrNone, TupleOrNone, print_unknown_options, populate_with_data, perform_checks, override_expected_value
+from .engine import StrOrNone, TupleOrNone, ChecklistObjType, print_unknown_options, populate_with_data, perform_checks, override_expected_value
 
 
 def _open(file: str, *args, **kwargs) -> TextIO:
@@ -80,7 +80,7 @@ def detect_compiler(fname: str) -> Tuple[StrOrNone, str]:
     sys.exit(f'[!] ERROR: invalid GCC_VERSION and CLANG_VERSION: {gcc_version} {clang_version}')
 
 
-def print_checklist(mode: StrOrNone, checklist: List, with_results: bool) -> None:
+def print_checklist(mode: StrOrNone, checklist: List[ChecklistObjType], with_results: bool) -> None:
     if mode == 'json':
         output = []
         for opt in checklist:
@@ -234,7 +234,7 @@ def main() -> None:
         if mode != 'json':
             print(f'[+] Special report mode: {mode}')
 
-    config_checklist = [] # type: List
+    config_checklist = [] # type: List[ChecklistObjType]
 
     if args.config:
         if args.print:
@@ -367,7 +367,7 @@ def main() -> None:
         if mode and mode not in ('verbose', 'json'):
             sys.exit(f'[!] ERROR: wrong mode "{mode}" for --print')
         arch = args.print
-        assert arch, 'unexpected empty arch from ArgumentParser'
+        assert(arch), 'unexpected empty arch from ArgumentParser'
         add_kconfig_checks(config_checklist, arch)
         add_cmdline_checks(config_checklist, arch)
         add_sysctl_checks(config_checklist, arch)
@@ -377,11 +377,15 @@ def main() -> None:
         sys.exit(0)
 
     if args.generate:
-        assert(args.config is None and args.cmdline is None and args.sysctl is None and args.print is None), 'unexpected args'
+        assert(args.config is None and
+               args.cmdline is None and
+               args.sysctl is None and
+               args.print is None), \
+               'unexpected args'
         if mode:
             sys.exit(f'[!] ERROR: wrong mode "{mode}" for --generate')
         arch = args.generate
-        assert arch, 'unexpected empty arch from ArgumentParser'
+        assert(arch), 'unexpected empty arch from ArgumentParser'
         add_kconfig_checks(config_checklist, arch)
         print(f'CONFIG_{arch}=y') # the Kconfig fragment should describe the microarchitecture
         for opt in config_checklist: