src/transformers/commands/add_new_model_like.py/remove_attributes
def remove_attributes(obj, target_attr):
    """Remove `target_attr` in `obj`."""
    lines = obj.split(os.linesep)

    target_idx = None
    for idx, line in enumerate(lines):
        # search for assignment
        if line.lstrip().startswith(f"{target_attr} = "):
            target_idx = idx
            break
        # search for function/method definition
        elif line.lstrip().startswith(f"def {target_attr}("):
            target_idx = idx
            break

    # target not found
    if target_idx is None:
        return obj

    line = lines[target_idx]
    indent_level = find_indent(line)
    # forward pass to find the ending of the block (including empty lines)
    parsed = extract_block("\n".join(lines[target_idx:]), indent_level)
    num_lines = len(parsed.split("\n"))
    for idx in range(num_lines):
        lines[target_idx + idx] = None

    # backward pass to find comments or decorator
    for idx in range(target_idx - 1, -1, -1):
        line = lines[idx]
        if (line.lstrip().startswith("#") or line.lstrip().startswith("@")) and find_indent(line) == indent_level:
            lines[idx] = None
        else:
            break

    new_obj = os.linesep.join([x for x in lines if x is not None])

    return new_obj