Merge strings that were split across multiple lines using line-continuation backslashes. Returns: Ok(new_line), if @line contains backslash line-continuation characters. OR Err(CannotTransform), otherwise.
(
line: Line, string_indices: list[int]
)
| 503 | |
| 504 | @staticmethod |
| 505 | def _remove_backslash_line_continuation_chars( |
| 506 | line: Line, string_indices: list[int] |
| 507 | ) -> TResult[Line]: |
| 508 | """ |
| 509 | Merge strings that were split across multiple lines using |
| 510 | line-continuation backslashes. |
| 511 | |
| 512 | Returns: |
| 513 | Ok(new_line), if @line contains backslash line-continuation |
| 514 | characters. |
| 515 | OR |
| 516 | Err(CannotTransform), otherwise. |
| 517 | """ |
| 518 | LL = line.leaves |
| 519 | |
| 520 | indices_to_transform = [] |
| 521 | for string_idx in string_indices: |
| 522 | string_leaf = LL[string_idx] |
| 523 | if ( |
| 524 | string_leaf.type == token.STRING |
| 525 | and "\\\n" in string_leaf.value |
| 526 | and not has_triple_quotes(string_leaf.value) |
| 527 | ): |
| 528 | indices_to_transform.append(string_idx) |
| 529 | |
| 530 | if not indices_to_transform: |
| 531 | return TErr( |
| 532 | "Found no string leaves that contain backslash line continuation" |
| 533 | " characters." |
| 534 | ) |
| 535 | |
| 536 | new_line = line.clone() |
| 537 | new_line.comments = line.comments.copy() |
| 538 | append_leaves(new_line, line, LL) |
| 539 | |
| 540 | for string_idx in indices_to_transform: |
| 541 | new_string_leaf = new_line.leaves[string_idx] |
| 542 | new_string_leaf.value = new_string_leaf.value.replace("\\\n", "") |
| 543 | |
| 544 | return Ok(new_line) |
| 545 | |
| 546 | def _merge_string_group( |
| 547 | self, line: Line, string_indices: list[int] |
no test coverage detected