diff --git a/mesonbuild/interpreterbase/disabler.py b/mesonbuild/interpreterbase/disabler.py index 81f526466..63b914e59 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 d990e6140..cfd72b5f4 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))