diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 0f7ef172f5a6..53a6cf666fbd 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1381,6 +1381,8 @@ def get_global_options(lang: str, comp_options = env.options.get(comp_key, []) link_options = env.options.get(largkey, []) + assert isinstance(comp_options, (str, list)), 'for mypy' + assert isinstance(link_options, (str, list)), 'for mypy' cargs = options.UserStringArrayOption( f'{lang}_{argkey.name}', diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py index 4055b21761c5..f972c692d6ca 100644 --- a/mesonbuild/envconfig.py +++ b/mesonbuild/envconfig.py @@ -13,6 +13,9 @@ from . import mlog from pathlib import Path +if T.TYPE_CHECKING: + from .options import ElementaryOptionValues + # These classes contains all the data pulled from configuration files (native # and cross file currently), and also assists with the reading environment @@ -153,7 +156,7 @@ class CMakeSkipCompilerTest(Enum): class Properties: def __init__( self, - properties: T.Optional[T.Dict[str, T.Optional[T.Union[str, bool, int, T.List[str]]]]] = None, + properties: T.Optional[T.Dict[str, ElementaryOptionValues]] = None, ): self.properties = properties or {} @@ -270,7 +273,9 @@ def __repr__(self) -> str: return f'' @classmethod - def from_literal(cls, literal: T.Dict[str, str]) -> 'MachineInfo': + def from_literal(cls, raw: T.Dict[str, ElementaryOptionValues]) -> 'MachineInfo': + assert all(isinstance(v, str) for v in raw.values()), 'for mypy' + literal = T.cast('T.Dict[str, str]', raw) minimum_literal = {'cpu', 'cpu_family', 'endian', 'system'} if set(literal) < minimum_literal: raise EnvironmentException( @@ -389,7 +394,7 @@ class BinaryTable: def __init__( self, - binaries: T.Optional[T.Dict[str, T.Union[str, T.List[str]]]] = None, + binaries: T.Optional[T.Mapping[str, ElementaryOptionValues]] = None, ): self.binaries: T.Dict[str, T.List[str]] = {} if binaries: diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 887e2d120c17..adbc12f7f42c 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -41,10 +41,9 @@ from mesonbuild import envconfig if T.TYPE_CHECKING: - from configparser import ConfigParser - from .compilers import Compiler from .compilers.mixins.visualstudio import VisualStudioLikeCompiler + from .options import ElementaryOptionValues from .wrap.wrap import Resolver from . import cargo @@ -633,7 +632,7 @@ def __init__(self, source_dir: str, build_dir: str, cmd_options: coredata.Shared # # Note that order matters because of 'buildtype', if it is after # 'optimization' and 'debug' keys, it override them. - self.options: T.MutableMapping[OptionKey, T.Union[str, T.List[str]]] = collections.OrderedDict() + self.options: T.MutableMapping[OptionKey, ElementaryOptionValues] = collections.OrderedDict() ## Read in native file(s) to override build machine configuration @@ -702,7 +701,8 @@ def __init__(self, source_dir: str, build_dir: str, cmd_options: coredata.Shared # Store a global state of Cargo dependencies self.cargo: T.Optional[cargo.Interpreter] = None - def _load_machine_file_options(self, config: 'ConfigParser', properties: Properties, machine: MachineChoice) -> None: + def _load_machine_file_options(self, config: T.Mapping[str, T.Mapping[str, ElementaryOptionValues]], + properties: Properties, machine: MachineChoice) -> None: """Read the contents of a Machine file and put it in the options store.""" # Look for any options in the deprecated paths section, warn about @@ -712,6 +712,7 @@ def _load_machine_file_options(self, config: 'ConfigParser', properties: Propert if paths: mlog.deprecation('The [paths] section is deprecated, use the [built-in options] section instead.') for k, v in paths.items(): + assert isinstance(v, (str, list)), 'for mypy' self.options[OptionKey.from_string(k).evolve(machine=machine)] = v # Next look for compiler options in the "properties" section, this is @@ -724,6 +725,7 @@ def _load_machine_file_options(self, config: 'ConfigParser', properties: Propert for k, v in properties.properties.copy().items(): if k in deprecated_properties: mlog.deprecation(f'{k} in the [properties] section of the machine file is deprecated, use the [built-in options] section.') + assert isinstance(v, (str, list)), 'for mypy' self.options[OptionKey.from_string(k).evolve(machine=machine)] = v del properties.properties[k] diff --git a/run_mypy.py b/run_mypy.py index 4f7a6317be57..afa5531cde24 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -36,6 +36,7 @@ # 'mesonbuild/coredata.py', 'mesonbuild/depfile.py', 'mesonbuild/envconfig.py', + 'mesonbuild/environment.py', 'mesonbuild/interpreter/compiler.py', 'mesonbuild/interpreter/mesonmain.py', 'mesonbuild/interpreter/interpreterobjects.py',