From 921c2370a722cbaa42bd256c699fae3185084939 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 17:36:25 -0500 Subject: Replace some type comments with annotations --- mesonbuild/environment.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mesonbuild/environment.py') diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index ff7ae3a..c5cccf3 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -488,7 +488,7 @@ class Environment: os.makedirs(self.log_dir, exist_ok=True) os.makedirs(self.info_dir, exist_ok=True) try: - self.coredata = coredata.load(self.get_build_dir()) # type: coredata.CoreData + self.coredata: coredata.CoreData = coredata.load(self.get_build_dir()) self.first_invocation = False except FileNotFoundError: self.create_new_coredata(options) @@ -521,13 +521,13 @@ class Environment: # Similar to coredata.compilers, but lower level in that there is no # meta data, only names/paths. - binaries = PerMachineDefaultable() # type: PerMachineDefaultable[BinaryTable] + binaries: PerMachineDefaultable[BinaryTable] = PerMachineDefaultable() # Misc other properties about each machine. - properties = PerMachineDefaultable() # type: PerMachineDefaultable[Properties] + properties: PerMachineDefaultable[Properties] = PerMachineDefaultable() # CMake toolchain variables - cmakevars = PerMachineDefaultable() # type: PerMachineDefaultable[CMakeVariables] + cmakevars: PerMachineDefaultable[CMakeVariables] = PerMachineDefaultable() ## Setup build machine defaults -- cgit v1.1 From d4bcf05c39e650d9651b5f2c60e7c12d59367e9c Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 17:47:12 -0500 Subject: Annotate naked fundamental Python types Although mypy wasn't complaining, pyright was. --- mesonbuild/environment.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'mesonbuild/environment.py') diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index c5cccf3..4e943ba 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -178,7 +178,7 @@ def get_llvm_tool_names(tool: str) -> T.List[str]: '-15', # Debian development snapshot '-devel', # FreeBSD development snapshot ] - names = [] + names: T.List[str] = [] for suffix in suffixes: names.append(tool + suffix) return names @@ -197,15 +197,16 @@ def detect_scanbuild() -> T.List[str]: Return: a single-element list of the found scan-build binary ready to be passed to Popen() """ - exelist = [] + exelist: T.List[str] = [] if 'SCANBUILD' in os.environ: exelist = split_args(os.environ['SCANBUILD']) else: tools = get_llvm_tool_names('scan-build') for tool in tools: - if shutil.which(tool) is not None: - exelist = [shutil.which(tool)] + which = shutil.which(tool) + if which is not None: + exelist = [which] break if exelist: -- cgit v1.1 From b0f1f374e72db18ddfe94b1a56b64cec7e1c98c6 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 18:11:09 -0500 Subject: Add type annotations where they previously didn't exist --- mesonbuild/environment.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'mesonbuild/environment.py') diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 4e943ba..ce7c9f1 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -82,7 +82,7 @@ def _get_env_var(for_machine: MachineChoice, is_cross: bool, var_name: str) -> T return value -def detect_gcovr(min_version='3.3', log=False): +def detect_gcovr(min_version: str = '3.3', log: bool = False): gcovr_exe = 'gcovr' try: p, found = Popen_safe([gcovr_exe, '--version'])[0:2] @@ -271,7 +271,7 @@ def detect_windows_arch(compilers: CompilersDict) -> str: return 'x86' return os_arch -def any_compiler_has_define(compilers: CompilersDict, define): +def any_compiler_has_define(compilers: CompilersDict, define: str) -> bool: for c in compilers.values(): try: if c.has_builtin_define(define): @@ -814,7 +814,7 @@ class Environment: return is_object(fname) @lru_cache(maxsize=None) - def is_library(self, fname): + def is_library(self, fname: mesonlib.FileOrString): return is_library(fname) def lookup_binary_entry(self, for_machine: MachineChoice, name: str) -> T.Optional[T.List[str]]: @@ -874,7 +874,7 @@ class Environment: def get_datadir(self) -> str: return self.coredata.get_option(OptionKey('datadir')) - def get_compiler_system_lib_dirs(self, for_machine: MachineChoice): + def get_compiler_system_lib_dirs(self, for_machine: MachineChoice) -> T.List[str]: for comp in self.coredata.compilers[for_machine].values(): if comp.id == 'clang': index = 1 @@ -893,7 +893,7 @@ class Environment: out = out.split('\n')[index].lstrip('libraries: =').split(':') return [os.path.normpath(p) for p in out] - def get_compiler_system_include_dirs(self, for_machine: MachineChoice): + def get_compiler_system_include_dirs(self, for_machine: MachineChoice) -> T.List[str]: for comp in self.coredata.compilers[for_machine].values(): if comp.id == 'clang': break -- cgit v1.1