MCPcopy
hub / github.com/psf/black / _remove_backslash_line_continuation_chars

Method _remove_backslash_line_continuation_chars

src/black/trans.py:505–544  ·  view source on GitHub ↗

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]
    )

Source from the content-addressed store, hash-verified

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]

Callers 1

do_transformMethod · 0.95

Calls 8

has_triple_quotesFunction · 0.90
append_leavesFunction · 0.90
OkClass · 0.90
TErrFunction · 0.85
copyMethod · 0.80
replaceMethod · 0.80
appendMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected