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

Function evaluate_subscript

src/smolagents/local_python_executor.py:921–938  ·  view source on GitHub ↗
(
    subscript: ast.Subscript,
    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

919
920
921def evaluate_subscript(
922 subscript: ast.Subscript,
923 state: dict[str, Any],
924 static_tools: dict[str, Callable],
925 custom_tools: dict[str, Callable],
926 authorized_imports: list[str],
927) -> Any:
928 index = evaluate_ast(subscript.slice, state, static_tools, custom_tools, authorized_imports)
929 value = evaluate_ast(subscript.value, state, static_tools, custom_tools, authorized_imports)
930 try:
931 return value[index]
932 except (KeyError, IndexError, TypeError) as e:
933 error_message = f"Could not index {value} with '{index}': {type(e).__name__}: {e}"
934 if isinstance(index, str) and isinstance(value, Mapping):
935 close_matches = difflib.get_close_matches(index, list(value.keys()))
936 if len(close_matches) > 0:
937 error_message += f". Maybe you meant one of these indexes instead: {str(close_matches)}"
938 raise InterpreterError(error_message) from e
939
940
941def evaluate_name(

Calls 2

evaluate_astFunction · 0.85
InterpreterErrorClass · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…