diff --git a/leval/evaluator.py b/leval/evaluator.py index 6217542..55ee2c3 100644 --- a/leval/evaluator.py +++ b/leval/evaluator.py @@ -53,6 +53,7 @@ def __init__( max_time: Optional[float] = None, allowed_constant_types: Optional[Iterable[type]] = None, allowed_container_types: Optional[Iterable[type]] = None, + loose_is_operator: bool = True, ): """ Initialize an evaluator with access to the given evaluation universe. @@ -62,6 +63,7 @@ def __init__( self.universe = universe self.max_depth = _default_if_none(max_depth, self.default_max_depth) self.max_time = float(max_time or 0) + self.loose_is_operator = bool(loose_is_operator) self.allowed_constant_types = frozenset( _default_if_none( allowed_constant_types, @@ -123,7 +125,7 @@ def visit_Compare(self, node): # noqa: D102 if len(node.ops) != 1: raise InvalidOperation("Only simple comparisons are supported", node=node) op = node.ops[0] - if isinstance(op, (ast.Is, ast.IsNot)): + if self.loose_is_operator and isinstance(op, (ast.Is, ast.IsNot)): left = self._visit_or_none(node.left) right = self._visit_or_none(node.comparators[0]) else: