Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 170 additions & 35 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,191 @@ check_untyped_defs = True
allow_redefinition_new = True
local_partial_types = True

[mypy-mesonbuild.cmdline]
[mypy-mesonbuild.*]
strict_optional = True

[mypy-mesonbuild.coredata]
strict_optional = True
[mypy-mesonbuild.ast.interpreter]
strict_optional = False

[mypy-mesonbuild.depfile]
strict_optional = True
[mypy-mesonbuild.ast.introspection]
strict_optional = False

[mypy-mesonbuild.envconfig]
strict_optional = True
[mypy-mesonbuild.backend.backends]
strict_optional = False

[mypy-mesonbuild.environment]
strict_optional = True
[mypy-mesonbuild.backend.ninjabackend]
strict_optional = False

[mypy-mesonbuild.machinefile]
strict_optional = True
[mypy-mesonbuild.backend.nonebackend]
strict_optional = False

[mypy-mesonbuild.mcompile]
strict_optional = True
[mypy-mesonbuild.backend.vs2010backend]
strict_optional = False

[mypy-mesonbuild.mconf]
strict_optional = True
[mypy-mesonbuild.backend.xcodebackend]
strict_optional = False

[mypy-mesonbuild.mdevenv]
strict_optional = True
[mypy-mesonbuild.build]
strict_optional = False

[mypy-mesonbuild.mdist]
strict_optional = True
[mypy-mesonbuild.cargo.interpreter]
strict_optional = False

[mypy-mesonbuild.mesondata]
strict_optional = True
[mypy-mesonbuild.cmake.executor]
strict_optional = False

[mypy-mesonbuild.mesonmain]
strict_optional = True
[mypy-mesonbuild.cmake.interpreter]
strict_optional = False

[mypy-mesonbuild.minit]
strict_optional = True
[mypy-mesonbuild.cmake.toolchain]
strict_optional = False

[mypy-mesonbuild.minstall]
strict_optional = True
[mypy-mesonbuild.cmake.tracetargets]
strict_optional = False

[mypy-mesonbuild.mlog]
strict_optional = True
[mypy-mesonbuild.compilers.*]
strict_optional = False

[mypy-mesonbuild.programs]
strict_optional = True
[mypy-mesonbuild.dependencies.base]
strict_optional = False

[mypy-mesonbuild.scripts.symbolextractor]
strict_optional = True
[mypy-mesonbuild.dependencies.boost]
strict_optional = False

[mypy-mesonbuild.tooldetect]
strict_optional = True
[mypy-mesonbuild.dependencies.configtool]
strict_optional = False

[mypy-mesonbuild.dependencies.cuda]
strict_optional = False

[mypy-mesonbuild.dependencies.detect]
strict_optional = False

[mypy-mesonbuild.dependencies.dev]
strict_optional = False

[mypy-mesonbuild.dependencies.dub]
strict_optional = False

[mypy-mesonbuild.dependencies.framework]
strict_optional = False

[mypy-mesonbuild.dependencies.hdf5]
strict_optional = False

[mypy-mesonbuild.dependencies.misc]
strict_optional = False

[mypy-mesonbuild.dependencies.mpi]
strict_optional = False

[mypy-mesonbuild.dependencies.pkgconfig]
strict_optional = False

[mypy-mesonbuild.dependencies.python]
strict_optional = False

[mypy-mesonbuild.dependencies.qt]
strict_optional = False

[mypy-mesonbuild.dependencies.ui]
strict_optional = False

[mypy-mesonbuild.interpreterbase.interpreterbase]
strict_optional = False

[mypy-mesonbuild.interpreterbase.baseobjects]
strict_optional = False

[mypy-mesonbuild.interpreterbase.decorators]
strict_optional = False

[mypy-mesonbuild.interpreter.interpreter]
strict_optional = False

[mypy-mesonbuild.interpreter.interpreterobjects]
strict_optional = False

[mypy-mesonbuild.interpreter.compiler]
strict_optional = False

[mypy-mesonbuild.interpreter.dependencyfallbacks]
strict_optional = False

[mypy-mesonbuild.linkers.detect]
strict_optional = False

[mypy-mesonbuild.mformat]
strict_optional = False

[mypy-mesonbuild.mintro]
strict_optional = False

[mypy-mesonbuild.modules]
strict_optional = False

[mypy-mesonbuild.modules.cmake]
strict_optional = False

[mypy-mesonbuild.modules.codegen]
strict_optional = False

[mypy-mesonbuild.modules.cuda]
strict_optional = False

[mypy-mesonbuild.modules.gnome]
strict_optional = False

[mypy-mesonbuild.modules.rust]
strict_optional = False

[mypy-mesonbuild.modules.pkgconfig]
strict_optional = False

[mypy-mesonbuild.modules.python]
strict_optional = False

[mypy-mesonbuild.modules._qt]
strict_optional = False

[mypy-mesonbuild.modules.i18n]
strict_optional = False

[mypy-mesonbuild.mparser]
strict_optional = False

[mypy-mesonbuild.msetup]
strict_optional = False

[mypy-mesonbuild.msubprojects]
strict_optional = False

[mypy-mesonbuild.mtest]
strict_optional = False

[mypy-mesonbuild.optinterpreter]
strict_optional = False

[mypy-mesonbuild.options]
strict_optional = False

[mypy-mesonbuild.rewriter]
strict_optional = False

[mypy-mesonbuild.wrap.wrap]
strict_optional = False

[mypy-mesonbuild.wrap.wraptool]
strict_optional = False

[mypy-mesonbuild.scripts.coverage]
strict_optional = False

[mypy-mesonbuild.scripts.scanbuild]
strict_optional = False

[mypy-mesonbuild.scripts.depfixer]
strict_optional = False

[mypy-mesonbuild.utils.universal]
strict_optional = False
2 changes: 1 addition & 1 deletion mesonbuild/cargo/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DictMergeValue(ConvertValue):
def __init__(self, func: T.Callable[[T.Any], T.List[object]],
merge_key: T.Callable[[T.Any], str],
out_key: T.Callable[[T.Any], str],
base: T.Mapping[str, object] = None) -> None:
base: T.Mapping[str, object]) -> None:
super().__init__(func, base)
self.merge_key = merge_key
self.out_key = out_key
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/cargo/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SemVer:

__slots__ = ('_v', 'specified_count')

def __init__(self, in_: str | list[int | str] = None) -> None:
def __init__(self, in_: str | list[int | str]) -> None:
vec: list[int | str]
if isinstance(in_, str):
vec = []
Expand Down
3 changes: 2 additions & 1 deletion mesonbuild/cmake/traceparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def strip_properties(self) -> None:
self.properties[key] = [x.strip() for x in val]
assert all(';' not in x for x in self.properties[key])

# FIXME: name can be empty here, so this is not quite a CMakeTarget
class CMakeGeneratorTarget(CMakeTarget):
def __init__(self, name: str) -> None:
super().__init__(name, 'CUSTOM', {})
Expand Down Expand Up @@ -395,7 +396,7 @@ def _cmake_add_library(self, tline: CMakeTraceLine) -> None:
else:
self.targets[args[0]] = CMakeTarget(args[0], 'NORMAL', {}, tline=tline)

def _cmake_add_custom_command(self, tline: CMakeTraceLine, name: T.Optional[str] = None) -> None:
def _cmake_add_custom_command(self, tline: CMakeTraceLine, name: str = '') -> None:
# DOC: https://cmake.org/cmake/help/latest/command/add_custom_command.html
args = self._flatten_args(list(tline.args)) # Commands can be passed as ';' separated lists

Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/interpreter/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def wrapped(*wrapped_args: T.Any, **wrapped_kwargs: T.Any) -> T.Any:
raise MesonBugException(f'cannot use @apply_machine_map if the object is a {type(wrapped_args[0])}')

_, _, kwargs, _ = get_callee_args(wrapped_args)
if kwargs is None:
raise MesonBugException('cannot use @apply_machine_map if the function does not take keyword arguments')
if 'native' in kwargs:
s.apply_machine_map_to_kwargs(T.cast('MachineMapArgs', kwargs))

Expand Down
7 changes: 4 additions & 3 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
TEST_KWS,
NoneType,
in_set_validator,
env_convertor_with_method
env_convertor,
env_validator,
)
from . import primitives as P_OBJ

Expand Down Expand Up @@ -3202,13 +3203,13 @@ def func_environment(self, node: mparser.FunctionNode, args: T.Tuple[T.Union[Non
init = args[0]
if init is not None:
FeatureNew.single_use('environment positional arguments', '0.52.0', self.subproject, location=node)
msg = ENV_KW.validator(init)
msg = env_validator(init)
if msg:
raise InvalidArguments(f'"environment": {msg}')
if isinstance(init, dict) and any(i for i in init.values() if isinstance(i, list)):
FeatureNew.single_use('List of string in dictionary value', '0.62.0', self.subproject, location=node)
# the validator call above ensured that we have the correct type
return env_convertor_with_method(T.cast('FullEnvInitValueType', init), kwargs['method'], kwargs['separator'])
return env_convertor(T.cast('FullEnvInitValueType', init), kwargs['method'], kwargs['separator'])
return EnvironmentVariables()

@typed_pos_args('join_paths', varargs=str, min_varargs=1)
Expand Down
8 changes: 4 additions & 4 deletions mesonbuild/interpreter/mesonmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from ..mesonlib import MachineChoice
from ..options import OptionKey
from ..programs import Program, ExternalProgram
from ..interpreter.type_checking import ENV_KW, ENV_METHOD_KW, ENV_SEPARATOR_KW, env_convertor_with_method
from ..interpreter.type_checking import ENV_METHOD_KW, ENV_SEPARATOR_KW, env_convertor
from ..interpreterbase import (MesonInterpreterObject, FeatureNew, FeatureDeprecated, FeatureBroken,
typed_pos_args, noArgsFlattening, noPosargs, noKwargs,
typed_kwargs, KwargInfo, InterpreterException, InterpreterObject)
from .decorators import apply_machine_map
from .primitives import MesonVersionString
from .type_checking import NATIVE_KW, NoneType
from .type_checking import NATIVE_KW, NoneType, env_validator

if T.TYPE_CHECKING:
from typing_extensions import Literal, TypedDict
Expand Down Expand Up @@ -488,10 +488,10 @@ def has_external_property_method(self, args: T.Tuple[str], kwargs: 'NativeKW') -
def add_devenv_method(self, args: T.Tuple[T.Union[str, list, dict, mesonlib.EnvironmentVariables]],
kwargs: 'AddDevenvKW') -> None:
env = args[0]
msg = ENV_KW.validator(env)
msg = env_validator(env)
if msg:
raise build.InvalidArguments(f'"add_devenv": {msg}')
converted = env_convertor_with_method(env, kwargs['method'], kwargs['separator'])
converted = env_convertor(env, kwargs['method'], kwargs['separator'])
assert isinstance(converted, mesonlib.EnvironmentVariables)
self.build.devenv.append(converted)

Expand Down
21 changes: 8 additions & 13 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def variables_convertor(contents: T.Union[str, T.List[str], T.Dict[str, str]]) -

DISABLER_KW: KwargInfo[bool] = KwargInfo('disabler', bool, default=False)

def _env_validator(value: T.Union[EnvironmentVariables, T.List['TYPE_var'], T.Dict[str, 'TYPE_var'], str, None],
only_dict_str: bool = True) -> T.Optional[str]:
def env_validator(value: T.Union[EnvironmentVariables, T.List['TYPE_var'], T.Dict[str, 'TYPE_var'], str, None],
only_dict_str: bool = True) -> T.Optional[str]:
def _splitter(v: str) -> T.Optional[str]:
split = v.split('=', 1)
if len(split) == 1:
Expand Down Expand Up @@ -231,7 +231,7 @@ def _splitter(v: str) -> T.Optional[str]:

def _options_validator(value: T.Union[EnvironmentVariables, T.List['TYPE_var'], T.Dict[str, 'TYPE_var'], str, None]) -> T.Optional[str]:
# Reusing the env validator is a little overkill, but nicer than duplicating the code
return _env_validator(value, only_dict_str=False)
return env_validator(value, only_dict_str=False)

def split_equal_string(input: str) -> T.Tuple[str, str]:
"""Split a string in the form `x=y`
Expand All @@ -241,11 +241,9 @@ def split_equal_string(input: str) -> T.Tuple[str, str]:
a, b = input.split('=', 1)
return (a, b)

# Split _env_convertor() and env_convertor_with_method() to make mypy happy.
# It does not want extra arguments in KwargInfo convertor callable.
def env_convertor_with_method(value: FullEnvInitValueType,
init_method: Literal['set', 'prepend', 'append'] = 'set',
separator: str = os.pathsep) -> EnvironmentVariables:
def env_convertor(value: FullEnvInitValueType,
init_method: Literal['set', 'prepend', 'append'] = 'set',
separator: str = os.pathsep) -> EnvironmentVariables:
if isinstance(value, str):
return EnvironmentVariables(dict([split_equal_string(value)]), init_method, separator)
elif isinstance(value, list):
Expand All @@ -256,14 +254,11 @@ def env_convertor_with_method(value: FullEnvInitValueType,
return EnvironmentVariables()
return value

def _env_convertor(value: FullEnvInitValueType) -> EnvironmentVariables:
return env_convertor_with_method(value)

ENV_KW: KwargInfo[T.Union[EnvironmentVariables, T.List, T.Dict, str, None]] = KwargInfo(
'env',
(EnvironmentVariables, list, dict, str, NoneType),
validator=_env_validator,
convertor=_env_convertor,
validator=env_validator,
convertor=env_convertor,
)

DEPFILE_KW: KwargInfo[T.Optional[str]] = KwargInfo(
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreterbase/baseobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InterpreterObject:
TRIVIAL_OPERATORS: T.Dict[
MesonOperator,
T.Tuple[
T.Union[T.Type, T.Tuple[T.Type, ...]],
T.Type | T.Tuple[T.Type, ...] | None,
TYPE_op_func
]
] = {}
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreterbase/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class KwargInfo(T.Generic[_T]):
:param as_default: Extra values to treat as empty values. These are always considered to be broken.
"""
def __init__(self, name: str,
types: T.Union[T.Type[_T], T.Tuple[T.Union[T.Type[_T], ContainerTypeInfo], ...], ContainerTypeInfo],
types: T.Union[T.Type[None], T.Type[_T], T.Tuple[T.Union[T.Type[None], T.Type[_T], ContainerTypeInfo], ...], ContainerTypeInfo],
*, required: bool = False, listify: bool = False,
default: T.Optional[_T] = None,
since: T.Optional[str] = None,
Expand Down
Loading
Loading