Skip to content

_function_calls_to_object_side_effects

function_calls_to_object_side_effects(function_inspector, function_calls)

Turn the function calls into the side effects in terms of the Python objects. For example, "the object [1, 2, 3] was mutated."

Source code in lineapy/system_tracing/_function_calls_to_object_side_effects.py
27
28
29
30
31
32
33
34
35
36
37
38
39
def function_calls_to_object_side_effects(
    function_inspector: FunctionInspector,
    function_calls: Iterable[FunctionCall],
) -> Iterable[ObjectSideEffect]:
    """
    Turn the function calls into the side effects in terms of the Python objects.
    For example, "the object [1, 2, 3] was mutated."
    """
    for fc in function_calls:
        for side_effect in function_inspector.inspect(
            fc.fn, fc.args, fc.kwargs, fc.res
        ):
            yield from to_object_side_effects(side_effect, fc)

pointer_to_objects(pointer, function_call)

Translate a pointer to the actual values, based on the values in the function call.

Source code in lineapy/system_tracing/_function_calls_to_object_side_effects.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def pointer_to_objects(
    pointer: ValuePointer, function_call: FunctionCall
) -> Iterable[object]:
    """
    Translate a pointer to the actual values, based on the values in the function call.
    """
    if isinstance(pointer, PositionalArg):
        yield function_call.args[pointer.positional_argument_index]
    elif isinstance(pointer, KeywordArgument):
        yield function_call.kwargs[pointer.argument_keyword]
    elif isinstance(pointer, AllPositionalArgs):
        yield from function_call.args
    elif isinstance(pointer, BoundSelfOfFunction):
        if hasattr(function_call.fn, "__self__"):
            yield function_call.fn.__self__  # type: ignore
        else:
            yield from []
    elif isinstance(pointer, Result):
        yield function_call.res
    elif isinstance(pointer, ExternalState):
        yield LINEA_BUILTINS[pointer.external_state]
    else:
        raise NotImplementedError(str(type(pointer)))

Was this helpful?

Help us improve docs with your feedback!