Skip to content

Commit

Permalink
[ref] Factor out __remove_backslash_line_continuation_chars(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbugyi200 committed Dec 29, 2019
1 parent 1420e1c commit f480203
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions black.py
Original file line number Diff line number Diff line change
Expand Up @@ -2580,13 +2580,9 @@ def _my_regexp(self) -> str:

def _do_transform(self, line: Line, _string_idx: Optional[int]) -> Iterator[Line]:
# Merge strings that were split across multiple lines using backslashes.
for leaf in line.leaves:
if leaf.type == token.STRING and leaf.value.lstrip(STRING_PREFIX_CHARS)[
:3
] not in {'"""', "'''"}:
leaf.value = leaf.value.replace("\\\n", "")
new_line = self.__remove_backslash_line_continuation_chars(line)

(new_line, line_was_changed) = self.__merge_first_string_group(line)
(new_line, line_was_changed) = self.__merge_first_string_group(new_line)
while line_was_changed:
(new_line, line_was_changed) = self.__merge_first_string_group(new_line)

Expand Down Expand Up @@ -2732,6 +2728,29 @@ def __get_string_group_index(line: Line) -> Optional[int]:

return None

@staticmethod
def __remove_backslash_line_continuation_chars(line: Line) -> Line:
for leaf in line.leaves:
if (
leaf.type == token.STRING
and "\\\n" in leaf.value
and leaf.value.lstrip(STRING_PREFIX_CHARS)[:3] not in {'"""', "'''"}
):
break
else:
return line

new_line = line.clone()
new_line.comments = line.comments
append_leaves(new_line, line, line.leaves)
for leaf in new_line.leaves:
if leaf.type == token.STRING and leaf.value.lstrip(STRING_PREFIX_CHARS)[
:3
] not in {'"""', "'''"}:
leaf.value = leaf.value.replace("\\\n", "")

return new_line

@staticmethod
def __remove_bad_trailing_commas(line: Line) -> Line:
line_str = line_to_string(line)
Expand Down

0 comments on commit f480203

Please sign in to comment.