diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-08-29 19:39:50 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-09-01 19:17:01 +0200 |
commit | 86eda3c812e8b919dee485c0b6333671652ee30c (patch) | |
tree | 80fc1f8fadd91af9473151cdd3540f8daa57d821 | |
parent | 80bd35c646ba35f8ee9c0efdf28795f712cd7a2f (diff) | |
download | meson-86eda3c812e8b919dee485c0b6333671652ee30c.zip meson-86eda3c812e8b919dee485c0b6333671652ee30c.tar.gz meson-86eda3c812e8b919dee485c0b6333671652ee30c.tar.bz2 |
interpreter: Simplify Disabler logic
-rw-r--r-- | mesonbuild/interpreterbase/disabler.py | 12 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/interpreterbase.py | 12 |
2 files changed, 8 insertions, 16 deletions
diff --git a/mesonbuild/interpreterbase/disabler.py b/mesonbuild/interpreterbase/disabler.py index 81f5264..63b914e 100644 --- a/mesonbuild/interpreterbase/disabler.py +++ b/mesonbuild/interpreterbase/disabler.py @@ -12,16 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .baseobjects import MesonInterpreterObject +from .baseobjects import MesonInterpreterObject, TYPE_var, TYPE_kwargs import typing as T class Disabler(MesonInterpreterObject): - def __init__(self) -> None: - super().__init__() - self.methods.update({'found': self.found_method}) - - def found_method(self, args: T.Sequence[T.Any], kwargs: T.Dict[str, T.Any]) -> bool: - return False + def method_call(self, method_name: str, args: T.List[TYPE_var], kwargs: TYPE_kwargs) -> TYPE_var: + if method_name == 'found': + return False + return Disabler() def _is_arg_disabled(arg: T.Any) -> bool: if isinstance(arg, Disabler): diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index d990e61..cfd72b5 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -640,18 +640,12 @@ class InterpreterBase: return self.dict_method_call(obj, method_name, args, kwargs) if not isinstance(obj, InterpreterObject): raise InvalidArguments('Variable "%s" is not callable.' % object_name) - # Special case. This is the only thing you can do with a disabler - # object. Every other use immediately returns the disabler object. - if isinstance(obj, Disabler): - if method_name == 'found': - return False - else: - return Disabler() # TODO: InterpreterBase **really** shouldn't be in charge of checking this if method_name == 'extract_objects': - if not isinstance(obj, ObjectHolder): + if isinstance(obj, ObjectHolder): + self.validate_extraction(obj.held_object) + elif not isinstance(obj, Disabler): raise InvalidArguments(f'Invalid operation "extract_objects" on variable "{object_name}" of type {type(obj).__name__}') - self.validate_extraction(obj.held_object) obj.current_node = node return self._holderify(obj.method_call(method_name, args, kwargs)) |