From d732e27e461b0fd7939dfb34e41d9008dd8c1d82 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 18:08:06 -0500 Subject: [PATCH] Use more specific types Added type arguments where needed. --- mesonbuild/coredata.py | 4 ++-- mesonbuild/utils/universal.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 8f0fa6155..6fff66388 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -81,7 +81,7 @@ DEFAULT_YIELDING = False _T = T.TypeVar('_T') -def get_genvs_default_buildtype_list() -> list: +def get_genvs_default_buildtype_list() -> list[str]: # just debug, debugoptimized, and release for now # but this should probably be configurable through some extra option, alongside --genvslite. return buildtypelist[1:-2] @@ -374,7 +374,7 @@ class DependencyCache: self.__cmake_key = OptionKey('cmake_prefix_path', machine=for_machine) def __calculate_subkey(self, type_: DependencyCacheType) -> T.Tuple[str, ...]: - data: T.Dict[str, T.List[str]] = { + data: T.Dict[DependencyCacheType, T.List[str]] = { DependencyCacheType.PKG_CONFIG: stringlistify(self.__builtins[self.__pkg_conf_key].value), DependencyCacheType.CMAKE: stringlistify(self.__builtins[self.__cmake_key].value), DependencyCacheType.OTHER: [], diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index 3b7ca142f..f4c37ad92 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -41,7 +41,7 @@ if T.TYPE_CHECKING: from .._typing import ImmutableListProtocol from ..build import ConfigurationData - from ..coredata import KeyedOptionDictType, UserOption + from ..coredata import KeyedOptionDictType, UserOption, StrOrBytesPath from ..environment import Environment from ..compilers.compilers import Compiler from ..interpreterbase.baseobjects import SubProject @@ -194,14 +194,15 @@ class GitException(MesonException): self.output = output.strip() if output else '' GIT = shutil.which('git') -def git(cmd: T.List[str], workingdir: T.Union[str, bytes, os.PathLike], check: bool = False, **kwargs: T.Any) -> T.Tuple[subprocess.Popen, str, str]: - cmd = [GIT] + cmd +def git(cmd: T.List[str], workingdir: StrOrBytesPath, check: bool = False, **kwargs: T.Any) -> T.Tuple[subprocess.Popen[str], str, str]: + assert GIT is not None, 'Callers should make sure it exists' + cmd = [GIT, *cmd] p, o, e = Popen_safe(cmd, cwd=workingdir, **kwargs) if check and p.returncode != 0: raise GitException('Git command failed: ' + str(cmd), e) return p, o, e -def quiet_git(cmd: T.List[str], workingdir: T.Union[str, bytes, os.PathLike], check: bool = False) -> T.Tuple[bool, str]: +def quiet_git(cmd: T.List[str], workingdir: StrOrBytesPath, check: bool = False) -> T.Tuple[bool, str]: if not GIT: m = 'Git program not found.' if check: @@ -212,7 +213,7 @@ def quiet_git(cmd: T.List[str], workingdir: T.Union[str, bytes, os.PathLike], ch return False, e return True, o -def verbose_git(cmd: T.List[str], workingdir: T.Union[str, bytes, os.PathLike], check: bool = False) -> bool: +def verbose_git(cmd: T.List[str], workingdir: StrOrBytesPath, check: bool = False) -> bool: if not GIT: m = 'Git program not found.' if check: @@ -595,7 +596,7 @@ class PerMachineDefaultable(PerMachine[T.Optional[_T]]): return m.default_missing() -class PerThreeMachineDefaultable(PerMachineDefaultable, PerThreeMachine[T.Optional[_T]]): +class PerThreeMachineDefaultable(PerMachineDefaultable[T.Optional[_T]], PerThreeMachine[T.Optional[_T]]): """Extends `PerThreeMachine` with the ability to default from `None`s. """ def __init__(self) -> None: @@ -1259,7 +1260,7 @@ def get_variable_regex(variable_format: Literal['meson', 'cmake', 'cmake@'] = 'm regex = re.compile(r'(?:\\\\)+(?=\\?\$)|\\\${|\${([-a-zA-Z0-9_]+)}') return regex -def do_conf_str(src: str, data: list, confdata: 'ConfigurationData', +def do_conf_str(src: str, data: T.List[str], confdata: 'ConfigurationData', variable_format: Literal['meson', 'cmake', 'cmake@'], encoding: str = 'utf-8', subproject: T.Optional[SubProject] = None) -> T.Tuple[T.List[str], T.Set[str], bool]: def line_is_valid(line: str, variable_format: str) -> bool: