aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/base.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-01 13:48:00 -0700
committerDaniel Mensinger <daniel@mensinger-ka.de>2020-09-02 11:23:45 +0200
commitec68e4fd5ab2674d88c58001b8e7bb42d76ff3a1 (patch)
treedf8b8d494ddf37bcec13cd97a9f2f48e1d4bcb9f /mesonbuild/dependencies/base.py
parent0755be50482ed21cf5022d7880fbbae8a73747e1 (diff)
downloadmeson-ec68e4fd5ab2674d88c58001b8e7bb42d76ff3a1.zip
meson-ec68e4fd5ab2674d88c58001b8e7bb42d76ff3a1.tar.gz
meson-ec68e4fd5ab2674d88c58001b8e7bb42d76ff3a1.tar.bz2
dependencies: Fix type of dependency_factory decorator
There was both a straight up bug in the type signature (the return type is List[Callable[[], Dependency]] not List[Type[Dependency]]), and in the way the arguments are assembled. Typing is pretty limited in it's ability to express decorators, so the best mypy can do is check the return types (I think). I've done what the docs suggest and it's stopped complaining.
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r--mesonbuild/dependencies/base.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index f581c06..85fb167 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -2498,10 +2498,11 @@ def strip_system_libdirs(environment, for_machine: MachineChoice, link_args):
return [l for l in link_args if l not in exclude]
-def process_method_kw(possible: T.List[DependencyMethods], kwargs) -> T.List[DependencyMethods]:
- method = kwargs.get('method', 'auto')
+def process_method_kw(possible: T.Iterable[DependencyMethods], kwargs) -> T.List[DependencyMethods]:
+ method = kwargs.get('method', 'auto') # type: T.Union[DependencyMethods, str]
if isinstance(method, DependencyMethods):
- return method
+ return [method]
+ # TODO: try/except?
if method not in [e.value for e in DependencyMethods]:
raise DependencyException('method {!r} is invalid'.format(method))
method = DependencyMethods(method)
@@ -2519,26 +2520,23 @@ def process_method_kw(possible: T.List[DependencyMethods], kwargs) -> T.List[Dep
# Set the detection method. If the method is set to auto, use any available method.
# If method is set to a specific string, allow only that detection method.
if method == DependencyMethods.AUTO:
- methods = possible
+ methods = list(possible)
elif method in possible:
methods = [method]
else:
raise DependencyException(
'Unsupported detection method: {}, allowed methods are {}'.format(
method.value,
- mlog.format_list([x.value for x in [DependencyMethods.AUTO] + possible])))
+ mlog.format_list([x.value for x in [DependencyMethods.AUTO] + list(possible)])))
return methods
if T.TYPE_CHECKING:
- FactoryType = T.Callable[[Environment, MachineChoice, T.Dict[str, T.Any]],
- T.List['DependencyType']]
- FullFactoryType = T.Callable[[Environment, MachineChoice, T.Dict[str, T.Any], T.Set[DependencyMethods]],
- T.List['DependencyType']]
+ FactoryType = T.TypeVar('FactoryType', bound=T.Callable[..., T.List[T.Callable[[], 'Dependency']]])
-def factory_methods(methods: T.Set[DependencyMethods]) -> 'FactoryType':
+def factory_methods(methods: T.Set[DependencyMethods]) -> T.Callable[['FactoryType'], 'FactoryType']:
"""Decorator for handling methods for dependency factory functions.
This helps to make factory functions self documenting
@@ -2547,13 +2545,13 @@ def factory_methods(methods: T.Set[DependencyMethods]) -> 'FactoryType':
>>> pass
"""
- def inner(func: 'FullFactoryType') -> 'FactoryType':
+ def inner(func: 'FactoryType') -> 'FactoryType':
@functools.wraps(func)
- def wrapped(env: Environment, for_machine: MachineChoice, kwargs: T.Dict[str, T.Any]) -> T.List['DependencyType']:
+ def wrapped(env: Environment, for_machine: MachineChoice, kwargs: T.Dict[str, T.Any]) -> T.List[T.Callable[[], 'Dependency']]:
return func(env, for_machine, kwargs, process_method_kw(methods, kwargs))
- return wrapped
+ return T.cast('FactoryType', wrapped)
return inner