From b821a0351136b3b3872e2ba9da8f7c67c4275449 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 29 Aug 2022 20:06:11 -0400 Subject: dependencies: use better internal representation of factory methods functools.partial preserves information about how the method was created, lambdas do not. Also, we just want to freeze the first argument and forward the rest anyway. This also lets us get rid of a mypy error that was being ignored. --- mesonbuild/dependencies/detect.py | 3 +-- mesonbuild/dependencies/factory.py | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'mesonbuild') diff --git a/mesonbuild/dependencies/detect.py b/mesonbuild/dependencies/detect.py index e4766cd..6e7d6d9 100644 --- a/mesonbuild/dependencies/detect.py +++ b/mesonbuild/dependencies/detect.py @@ -178,8 +178,7 @@ def _build_external_dependency_list(name: str, env: 'Environment', for_machine: if isinstance(packages[lname], type): entry1 = T.cast('T.Type[ExternalDependency]', packages[lname]) # mypy doesn't understand isinstance(..., type) if issubclass(entry1, ExternalDependency): - # TODO: somehow make mypy understand that entry1(env, kwargs) is OK... - func: T.Callable[[], 'ExternalDependency'] = lambda: entry1(env, kwargs) # type: ignore + func: T.Callable[[], 'ExternalDependency'] = functools.partial(entry1, env, kwargs) dep = [func] else: entry2 = T.cast('T.Union[DependencyFactory, WrappedFactoryFunc]', packages[lname]) diff --git a/mesonbuild/dependencies/factory.py b/mesonbuild/dependencies/factory.py index b26bbd6..d50ce0f 100644 --- a/mesonbuild/dependencies/factory.py +++ b/mesonbuild/dependencies/factory.py @@ -100,15 +100,15 @@ class DependencyFactory: ] = { # Just attach the correct name right now, either the generic name # or the method specific name. - DependencyMethods.EXTRAFRAMEWORK: lambda env, kwargs: framework_class(framework_name or name, env, kwargs), - DependencyMethods.PKGCONFIG: lambda env, kwargs: pkgconfig_class(pkgconfig_name or name, env, kwargs), - DependencyMethods.CMAKE: lambda env, kwargs: cmake_class(cmake_name or name, env, kwargs), - DependencyMethods.SYSTEM: lambda env, kwargs: system_class(name, env, kwargs), - DependencyMethods.BUILTIN: lambda env, kwargs: builtin_class(name, env, kwargs), + DependencyMethods.EXTRAFRAMEWORK: functools.partial(framework_class, framework_name or name), + DependencyMethods.PKGCONFIG: functools.partial(pkgconfig_class, pkgconfig_name or name), + DependencyMethods.CMAKE: functools.partial(cmake_class, cmake_name or name), + DependencyMethods.SYSTEM: functools.partial(system_class, name), + DependencyMethods.BUILTIN: functools.partial(builtin_class, name), DependencyMethods.CONFIG_TOOL: None, } if configtool_class is not None: - self.classes[DependencyMethods.CONFIG_TOOL] = lambda env, kwargs: configtool_class(name, env, kwargs) + self.classes[DependencyMethods.CONFIG_TOOL] = functools.partial(configtool_class, name) @staticmethod def _process_method(method: DependencyMethods, env: 'Environment', for_machine: MachineChoice) -> bool: -- cgit v1.1