From 7abd4d39c179f9cf4b8830d44d070b910db8a2d4 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 17 Jun 2022 14:05:25 -0700 Subject: [PATCH] interpreter: add type annotations to func_declare_dependency --- mesonbuild/interpreter/interpreter.py | 7 ++++--- mesonbuild/interpreter/kwargs.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 95a6e1d80..61c0b253e 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -691,7 +691,8 @@ class Interpreter(InterpreterBase, HoldableObject): KwargInfo('version', (str, NoneType)), KwargInfo('objects', ContainerTypeInfo(list, build.ExtractedObjects), listify=True, default=[], since='1.1.0'), ) - def func_declare_dependency(self, node, args, kwargs): + def func_declare_dependency(self, node: mparser.BaseNode, args: T.List[TYPE_var], + kwargs: kwtypes.FuncDeclareDependency) -> dependencies.Dependency: deps = kwargs['dependencies'] incs = self.extract_incdirs(kwargs) libs = kwargs['link_with'] @@ -2738,7 +2739,7 @@ class Interpreter(InterpreterBase, HoldableObject): install_tag=install_tag, data_type='configure')) return mesonlib.File.from_built_file(self.subdir, output) - def extract_incdirs(self, kwargs, key: str = 'include_directories'): + def extract_incdirs(self, kwargs, key: str = 'include_directories') -> T.List[build.IncludeDirs]: prospectives = extract_as_list(kwargs, key) if key == 'include_directories': for i in prospectives: @@ -2747,7 +2748,7 @@ class Interpreter(InterpreterBase, HoldableObject): f'Use include_directories({i!r}) instead', location=self.current_node) break - result = [] + result: T.List[build.IncludeDirs] = [] for p in prospectives: if isinstance(p, build.IncludeDirs): result.append(p) diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 2a1cd6173..48e483efc 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -12,6 +12,7 @@ from typing_extensions import TypedDict, Literal, Protocol from .. import build from .. import coredata from ..compilers import Compiler +from ..dependencies.base import Dependency from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString, OptionKey from ..modules.cmake import CMakeSubprojectOptions from ..programs import ExternalProgram @@ -360,3 +361,20 @@ class Jar(_BaseBuildTarget): main_class: str java_resources: T.Optional[build.StructuredSources] + + +class FuncDeclareDependency(TypedDict): + + compile_args: T.List[str] + d_import_dirs: T.List[T.Union[build.IncludeDirs, str]] + d_module_versions: T.List[T.Union[str, int]] + dependencies: T.List[Dependency] + extra_files: T.List[FileOrString] + include_directories: T.List[T.Union[build.IncludeDirs, str]] + link_args: T.List[str] + link_whole: T.List[T.Union[build.StaticLibrary, build.CustomTarget, build.CustomTargetIndex]] + link_with: T.List[build.LibTypes] + objects: T.List[build.ExtractedObjects] + sources: T.List[T.Union[FileOrString, build.GeneratedTypes]] + variables: T.Dict[str, str] + version: T.Optional[str]