From: Alexander Popov Date: Sun, 12 May 2024 13:44:29 +0000 (+0300) Subject: Fix mypy warning in _open() X-Git-Tag: v0.6.10~67^2~21 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=f0541cf75b3a4bf5db3a1812d42e6b47a4bd711b;p=kconfig-hardened-check.git 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. --- 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: