Use more specific types

Added type arguments where needed.
pull/11976/head
Tristan Partin 1 year ago
parent c1863f781b
commit d732e27e46
  1. 4
      mesonbuild/coredata.py
  2. 15
      mesonbuild/utils/universal.py

@ -81,7 +81,7 @@ DEFAULT_YIELDING = False
_T = T.TypeVar('_T') _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 # just debug, debugoptimized, and release for now
# but this should probably be configurable through some extra option, alongside --genvslite. # but this should probably be configurable through some extra option, alongside --genvslite.
return buildtypelist[1:-2] return buildtypelist[1:-2]
@ -374,7 +374,7 @@ class DependencyCache:
self.__cmake_key = OptionKey('cmake_prefix_path', machine=for_machine) self.__cmake_key = OptionKey('cmake_prefix_path', machine=for_machine)
def __calculate_subkey(self, type_: DependencyCacheType) -> T.Tuple[str, ...]: 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.PKG_CONFIG: stringlistify(self.__builtins[self.__pkg_conf_key].value),
DependencyCacheType.CMAKE: stringlistify(self.__builtins[self.__cmake_key].value), DependencyCacheType.CMAKE: stringlistify(self.__builtins[self.__cmake_key].value),
DependencyCacheType.OTHER: [], DependencyCacheType.OTHER: [],

@ -41,7 +41,7 @@ if T.TYPE_CHECKING:
from .._typing import ImmutableListProtocol from .._typing import ImmutableListProtocol
from ..build import ConfigurationData from ..build import ConfigurationData
from ..coredata import KeyedOptionDictType, UserOption from ..coredata import KeyedOptionDictType, UserOption, StrOrBytesPath
from ..environment import Environment from ..environment import Environment
from ..compilers.compilers import Compiler from ..compilers.compilers import Compiler
from ..interpreterbase.baseobjects import SubProject from ..interpreterbase.baseobjects import SubProject
@ -194,14 +194,15 @@ class GitException(MesonException):
self.output = output.strip() if output else '' self.output = output.strip() if output else ''
GIT = shutil.which('git') 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]: def git(cmd: T.List[str], workingdir: StrOrBytesPath, check: bool = False, **kwargs: T.Any) -> T.Tuple[subprocess.Popen[str], str, str]:
cmd = [GIT] + cmd assert GIT is not None, 'Callers should make sure it exists'
cmd = [GIT, *cmd]
p, o, e = Popen_safe(cmd, cwd=workingdir, **kwargs) p, o, e = Popen_safe(cmd, cwd=workingdir, **kwargs)
if check and p.returncode != 0: if check and p.returncode != 0:
raise GitException('Git command failed: ' + str(cmd), e) raise GitException('Git command failed: ' + str(cmd), e)
return p, o, 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: if not GIT:
m = 'Git program not found.' m = 'Git program not found.'
if check: 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 False, e
return True, o 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: if not GIT:
m = 'Git program not found.' m = 'Git program not found.'
if check: if check:
@ -595,7 +596,7 @@ class PerMachineDefaultable(PerMachine[T.Optional[_T]]):
return m.default_missing() 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. """Extends `PerThreeMachine` with the ability to default from `None`s.
""" """
def __init__(self) -> None: 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_]+)}') regex = re.compile(r'(?:\\\\)+(?=\\?\$)|\\\${|\${([-a-zA-Z0-9_]+)}')
return regex 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@'], variable_format: Literal['meson', 'cmake', 'cmake@'],
encoding: str = 'utf-8', subproject: T.Optional[SubProject] = None) -> T.Tuple[T.List[str], T.Set[str], bool]: 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: def line_is_valid(line: str, variable_format: str) -> bool:

Loading…
Cancel
Save