diff options
author | Patrik Teivonen <patrik.teivonen@qt.io> | 2022-06-06 08:46:13 +0300 |
---|---|---|
committer | Patrik Teivonen <patrik.teivonen@qt.io> | 2022-09-22 08:44:13 +0000 |
commit | 5cc5a8d307708f7ed3051d2bcd78e1e51cefa9f6 (patch) | |
tree | a006b72b16663888c8ef50c2486453e0dcff89e3 /packaging-tools/optionparser.py | |
parent | bd4fe3adf592fc2d84a95200873d8f62a4164f7c (diff) |
Add missing type hints, enable strict mypy checking
Enable --strict parameter in mypy.
Add missing type hints and resolve remaining type errors.
Change-Id: Id9547cc3351b88729930c577d4ed628780c1447b
Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
Diffstat (limited to 'packaging-tools/optionparser.py')
-rw-r--r-- | packaging-tools/optionparser.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/packaging-tools/optionparser.py b/packaging-tools/optionparser.py index b7d12e401..936113369 100644 --- a/packaging-tools/optionparser.py +++ b/packaging-tools/optionparser.py @@ -32,43 +32,44 @@ import argparse import os import sys from configparser import ConfigParser +from typing import Dict class PackagingOptions: """Utility class to read options from configuration file that follows .ini file format.""" - def __init__(self, conf_file): + def __init__(self, conf_file: str) -> None: if not os.path.isfile(conf_file): raise IOError(f"Not a valid file: {conf_file}") self.config = ConfigParser(os.environ) - self.config.optionxform = str + self.config.optionxform = str # type: ignore self.config.read(conf_file) - def config_section_map(self, section): + def config_section_map(self, section: str) -> Dict[str, str]: dict1 = {} options = self.config.options(section) for option in options: try: dict1[option] = self.config.get(section, option) - if dict1[option] == -1: + if dict1[option] == "-1": print(f"skip: {option}") except Exception: print(f"exception on {option}!") - dict1[option] = None + dict1[option] = "" return dict1 - def section_exists(self, section): + def section_exists(self, section: str) -> bool: return self.config.has_section(section) - def option_exists(self, section, option): + def option_exists(self, section: str, option: str) -> bool: return self.section_exists(section) and self.config.has_option(section, option) - def config_map(self): + def config_map(self) -> Dict[str, str]: dict1 = {} for section in self.config.sections(): dict1.update(self.config_section_map(section)) return dict1 - def verbose(self): + def verbose(self) -> None: for section in self.config.sections(): print(f"[{section}]") options = self.config.options(section) @@ -77,7 +78,7 @@ class PackagingOptions: print() -def get_pkg_options(conf_file_path): +def get_pkg_options(conf_file_path: str) -> PackagingOptions: return PackagingOptions(conf_file_path) |