Apply pre-sorted replacements in reverse order to avoid index shift.
(
lines: List[str],
replacements: List[Tuple[int, int, List[str]]],
)
| 738 | return replacements |
| 739 | |
| 740 | def _apply_replacements( |
| 741 | lines: List[str], |
| 742 | replacements: List[Tuple[int, int, List[str]]], |
| 743 | ) -> List[str]: |
| 744 | """Apply pre-sorted replacements in reverse order to avoid index shift.""" |
| 745 | result = list(lines) |
| 746 | for start_idx, old_len, new_segment in reversed(replacements): |
| 747 | del result[start_idx: start_idx + old_len] |
| 748 | for j, line in enumerate(new_segment): |
| 749 | result.insert(start_idx + j, line) |
| 750 | return result |
| 751 | |
| 752 | def apply_update_chunks( |
| 753 | file_path: str, |
no outgoing calls
no test coverage detected