diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-08-29 19:32:37 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-09-01 19:17:01 +0200 |
commit | 43a6b5bd5ea7d8f93d09b9962a8f47737641be53 (patch) | |
tree | 40bce373e06b2efc4a1ef74a3a3112b3a95d2b40 | |
parent | ea02c1c48a8a11aab78bd535d18fb17fdf62ae33 (diff) | |
download | meson-43a6b5bd5ea7d8f93d09b9962a8f47737641be53.zip meson-43a6b5bd5ea7d8f93d09b9962a8f47737641be53.tar.gz meson-43a6b5bd5ea7d8f93d09b9962a8f47737641be53.tar.bz2 |
interpreter: Remove permissive from _unholder
-rw-r--r-- | mesonbuild/interpreter/interpreter.py | 4 | ||||
-rw-r--r-- | mesonbuild/interpreter/interpreterobjects.py | 6 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/__init__.py | 4 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/_unholder.py | 10 |
4 files changed, 11 insertions, 13 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index c3e9b48..d4d5564 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2643,7 +2643,7 @@ This will become a hard error in the future.''', location=self.current_node) @typed_pos_args('get_variable', (str, Disabler), optargs=[object]) @noKwargs @noArgsFlattening - @permissive_unholder_return + @unholder_return def func_get_variable(self, node: mparser.BaseNode, args: T.Tuple[T.Union[str, Disabler], T.Optional[object]], kwargs: 'TYPE_kwargs') -> 'TYPE_var': varname, fallback = args @@ -2654,7 +2654,7 @@ This will become a hard error in the future.''', location=self.current_node) return self.variables[varname] except KeyError: if fallback is not None: - return fallback + return self._holderify(fallback) raise InterpreterException(f'Tried to get unknown variable "{varname}".') @typed_pos_args('is_variable', str) diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index b0fe512..78c7fb9 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -18,7 +18,7 @@ from ..interpreterbase import ( InterpreterObject, MesonInterpreterObject, ObjectHolder, MutableInterpreterObject, FeatureCheckBase, FeatureNewKwargs, FeatureNew, FeatureDeprecated, typed_pos_args, typed_kwargs, permittedKwargs, - noArgsFlattening, noPosargs, noKwargs, permissive_unholder_return, TYPE_var, TYPE_kwargs, TYPE_nvar, TYPE_nkwargs, + noArgsFlattening, noPosargs, noKwargs, unholder_return, TYPE_var, TYPE_kwargs, TYPE_nvar, TYPE_nkwargs, flatten, resolve_second_level_holders, InterpreterException, InvalidArguments, InvalidCode) from ..interpreter.type_checking import NoneType from ..dependencies import Dependency, ExternalLibrary, InternalDependency @@ -712,7 +712,7 @@ class SubprojectHolder(MesonInterpreterObject): @noKwargs @noArgsFlattening - @permissive_unholder_return + @unholder_return def get_variable_method(self, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> T.Union[TYPE_var, InterpreterObject]: if len(args) < 1 or len(args) > 2: raise InterpreterException('Get_variable takes one or two arguments.') @@ -727,7 +727,7 @@ class SubprojectHolder(MesonInterpreterObject): pass if len(args) == 2: - return args[1] + return self.held_object._holderify(args[1]) raise InvalidArguments(f'Requested variable "{varname}" not found.') diff --git a/mesonbuild/interpreterbase/__init__.py b/mesonbuild/interpreterbase/__init__.py index e630bbf..f237c2f 100644 --- a/mesonbuild/interpreterbase/__init__.py +++ b/mesonbuild/interpreterbase/__init__.py @@ -42,7 +42,7 @@ __all__ = [ 'stringArgs', 'noArgsFlattening', 'noSecondLevelHolderResolving', - 'permissive_unholder_return', + 'unholder_return', 'disablerIfNotFound', 'permittedKwargs', 'typed_operator', @@ -102,7 +102,7 @@ from .decorators import ( stringArgs, noArgsFlattening, noSecondLevelHolderResolving, - permissive_unholder_return, + unholder_return, disablerIfNotFound, permittedKwargs, typed_pos_args, diff --git a/mesonbuild/interpreterbase/_unholder.py b/mesonbuild/interpreterbase/_unholder.py index 55f3423..202f53b 100644 --- a/mesonbuild/interpreterbase/_unholder.py +++ b/mesonbuild/interpreterbase/_unholder.py @@ -18,20 +18,18 @@ from ..mesonlib import HoldableObject, MesonBugException import typing as T -def _unholder(obj: T.Union[TYPE_var, InterpreterObject], *, permissive: bool = False) -> TYPE_var: - if isinstance(obj, (bool, str)): +def _unholder(obj: T.Union[TYPE_var, InterpreterObject]) -> TYPE_var: + if isinstance(obj, str): return obj elif isinstance(obj, list): - return [_unholder(x, permissive=permissive) for x in obj] + return [_unholder(x) for x in obj] elif isinstance(obj, dict): - return {k: _unholder(v, permissive=permissive) for k, v in obj.items()} + return {k: _unholder(v) for k, v in obj.items()} elif isinstance(obj, ObjectHolder): assert isinstance(obj.held_object, HoldableTypes) return obj.held_object elif isinstance(obj, MesonInterpreterObject): return obj - elif isinstance(obj, HoldableObject) and permissive: - return obj elif isinstance(obj, HoldableObject): raise MesonBugException(f'Argument {obj} of type {type(obj).__name__} is not held by an ObjectHolder.') elif isinstance(obj, InterpreterObject): |