@@ -2580,13 +2580,9 @@ def _my_regexp(self) -> str:
2580
2580
2581
2581
def _do_transform (self , line : Line , _string_idx : Optional [int ]) -> Iterator [Line ]:
2582
2582
# Merge strings that were split across multiple lines using backslashes.
2583
- for leaf in line .leaves :
2584
- if leaf .type == token .STRING and leaf .value .lstrip (STRING_PREFIX_CHARS )[
2585
- :3
2586
- ] not in {'"""' , "'''" }:
2587
- leaf .value = leaf .value .replace ("\\ \n " , "" )
2583
+ new_line = self .__remove_backslash_line_continuation_chars (line )
2588
2584
2589
- (new_line , line_was_changed ) = self .__merge_first_string_group (line )
2585
+ (new_line , line_was_changed ) = self .__merge_first_string_group (new_line )
2590
2586
while line_was_changed :
2591
2587
(new_line , line_was_changed ) = self .__merge_first_string_group (new_line )
2592
2588
@@ -2732,6 +2728,29 @@ def __get_string_group_index(line: Line) -> Optional[int]:
2732
2728
2733
2729
return None
2734
2730
2731
+ @staticmethod
2732
+ def __remove_backslash_line_continuation_chars (line : Line ) -> Line :
2733
+ for leaf in line .leaves :
2734
+ if (
2735
+ leaf .type == token .STRING
2736
+ and "\\ \n " in leaf .value
2737
+ and leaf .value .lstrip (STRING_PREFIX_CHARS )[:3 ] not in {'"""' , "'''" }
2738
+ ):
2739
+ break
2740
+ else :
2741
+ return line
2742
+
2743
+ new_line = line .clone ()
2744
+ new_line .comments = line .comments
2745
+ append_leaves (new_line , line , line .leaves )
2746
+ for leaf in new_line .leaves :
2747
+ if leaf .type == token .STRING and leaf .value .lstrip (STRING_PREFIX_CHARS )[
2748
+ :3
2749
+ ] not in {'"""' , "'''" }:
2750
+ leaf .value = leaf .value .replace ("\\ \n " , "" )
2751
+
2752
+ return new_line
2753
+
2735
2754
@staticmethod
2736
2755
def __remove_bad_trailing_commas (line : Line ) -> Line :
2737
2756
line_str = line_to_string (line )
0 commit comments