from typing import List
from typing import Tuple


def _get_operation_and_return_line_indices(lines: List[str]) -> Tuple[int, int, int]:
    """
    Torch jit trace code is split into 4 sections: forward function signature, parameter getting, operations, and return
    statements.
    Each section can be identified by certain attributes.
    Identify the line indices marking the start of the parameter getting, operations, and return statements sections.
    :param lines: Lines of torch jit trace code.
    :return: A tuple of three integers corresponding to starting indices of the parameter getting, operations and return
    statements sections.
    """
    curr_index = 0
    parameter_index = 0
    operation_index = 0
    return_index = 0
    for line in lines:
        # Forward function signature lines have no '=' signs, so the first line to have one is the start of the
        # parameter getting section.
        if '=' in line and not parameter_index:
            parameter_index = curr_index

        # Parameter getting section only contains parentheses if it uses the 'getattr()' function.  Operation lines
        # don't use the getattr() function, so the first line with parentheses and no getattr() function is the start
        # of the operation section,
        if '(' in line and 'getattr' not in line and 'forward' not in line and not operation_index:
            operation_index = curr_index

        # Return sections lines all have 'return' within.
        if 'return' in line:
            return_index = curr_index
            break
        curr_index += 1
    return parameter_index, operation_index, return_index