MCPcopy
hub / github.com/huggingface/smolagents / evaluate_binop

Function evaluate_binop

src/smolagents/local_python_executor.py:730–767  ·  view source on GitHub ↗
(
    binop: ast.BinOp,
    state: dict[str, Any],
    static_tools: dict[str, Callable],
    custom_tools: dict[str, Callable],
    authorized_imports: list[str],
)

Source from the content-addressed store, hash-verified

728
729
730def evaluate_binop(
731 binop: ast.BinOp,
732 state: dict[str, Any],
733 static_tools: dict[str, Callable],
734 custom_tools: dict[str, Callable],
735 authorized_imports: list[str],
736) -> Any:
737 # Recursively evaluate the left and right operands
738 left_val = evaluate_ast(binop.left, state, static_tools, custom_tools, authorized_imports)
739 right_val = evaluate_ast(binop.right, state, static_tools, custom_tools, authorized_imports)
740
741 # Determine the operation based on the type of the operator in the BinOp
742 if isinstance(binop.op, ast.Add):
743 return left_val + right_val
744 elif isinstance(binop.op, ast.Sub):
745 return left_val - right_val
746 elif isinstance(binop.op, ast.Mult):
747 return left_val * right_val
748 elif isinstance(binop.op, ast.Div):
749 return left_val / right_val
750 elif isinstance(binop.op, ast.Mod):
751 return left_val % right_val
752 elif isinstance(binop.op, ast.Pow):
753 return left_val**right_val
754 elif isinstance(binop.op, ast.FloorDiv):
755 return left_val // right_val
756 elif isinstance(binop.op, ast.BitAnd):
757 return left_val & right_val
758 elif isinstance(binop.op, ast.BitOr):
759 return left_val | right_val
760 elif isinstance(binop.op, ast.BitXor):
761 return left_val ^ right_val
762 elif isinstance(binop.op, ast.LShift):
763 return left_val << right_val
764 elif isinstance(binop.op, ast.RShift):
765 return left_val >> right_val
766 else:
767 raise NotImplementedError(f"Binary operation {type(binop.op).__name__} is not implemented.")
768
769
770def evaluate_assign(

Callers 1

evaluate_astFunction · 0.85

Calls 1

evaluate_astFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…