(
subscript: ast.Subscript,
state: dict[str, Any],
static_tools: dict[str, Callable],
custom_tools: dict[str, Callable],
authorized_imports: list[str],
)
| 919 | |
| 920 | |
| 921 | def 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 | |
| 941 | def evaluate_name( |
searching dependent graphs…