interpreter: Simplify Disabler logic

pull/9202/head
Daniel Mensinger 3 years ago
parent 80bd35c646
commit 86eda3c812
  1. 12
      mesonbuild/interpreterbase/disabler.py
  2. 12
      mesonbuild/interpreterbase/interpreterbase.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):

@ -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))

Loading…
Cancel
Save