From f0541cf75b3a4bf5db3a1812d42e6b47a4bd711b Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 12 May 2024 16:44:29 +0300 Subject: [PATCH] Fix mypy warning in _open() kernel_hardening_checker/__init__.py:28: error: Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function) [assignment] Refactor the _open function to fix this and add the type hint by the way. --- kernel_hardening_checker/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index f4b7525..1522d4a 100644 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -14,7 +14,7 @@ import gzip import sys from argparse import ArgumentParser from collections import OrderedDict -from typing import List, Tuple +from typing import List, Tuple, TextIO import re import json from .__about__ import __version__ @@ -22,12 +22,12 @@ from .checks import add_kconfig_checks, add_cmdline_checks, normalize_cmdline_op from .engine import populate_with_data, perform_checks, override_expected_value -def _open(file: str, *args, **kwargs): - open_method = open +def _open(file: str, *args, **kwargs) -> TextIO: if file.endswith('.gz'): - open_method = gzip.open - - return open_method(file, *args, **kwargs) + f = gzip.open(file, *args, **kwargs) + else: + f = open(file, *args, **kwargs) + return f def detect_arch(fname: str, archs: List[str]) -> Tuple: -- 2.31.1