From dfa658fbd02239fa6481f97e6f81a42db3d9f871 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 12 May 2024 16:28:03 +0300 Subject: [PATCH] Fix mypy warning in json_dump() kernel_hardening_checker/engine.py:119: error: "None" has no attribute "startswith" [attr-defined] The `json_dump()` function printing the results should not be called for the OptCheck and ComplexOptCheck objects with empty results. --- kernel_hardening_checker/engine.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel_hardening_checker/engine.py b/kernel_hardening_checker/engine.py index 0bf0ad5..1e69c79 100644 --- a/kernel_hardening_checker/engine.py +++ b/kernel_hardening_checker/engine.py @@ -115,6 +115,7 @@ class OptCheck: "reason": self.reason, } if with_results: + assert self.result, f'unexpected empty result in {self.name}' dump["check_result"] = self.result dump["check_result_bool"] = self.result.startswith('OK') return dump @@ -230,6 +231,7 @@ class ComplexOptCheck: dump = self.opts[0].json_dump(False) if with_results: # Add the 'check_result' and 'check_result_bool' keys to the dictionary + assert self.result, f'unexpected empty result in {self.name}' dump["check_result"] = self.result dump["check_result_bool"] = self.result.startswith('OK') return dump -- 2.31.1