@@ -2579,7 +2579,6 @@ def _my_regexp(self) -> str:
2579
2579
return r"^[\s\S]*$"
2580
2580
2581
2581
def _do_transform (self , line : Line , _string_idx : Optional [int ]) -> Iterator [Line ]:
2582
- # Merge strings that were split across multiple lines using backslashes.
2583
2582
new_line = self .__remove_backslash_line_continuation_chars (line )
2584
2583
2585
2584
(new_line , line_was_changed ) = self .__merge_first_string_group (new_line )
@@ -2590,6 +2589,30 @@ def _do_transform(self, line: Line, _string_idx: Optional[int]) -> Iterator[Line
2590
2589
2591
2590
yield new_line
2592
2591
2592
+ @staticmethod
2593
+ def __remove_backslash_line_continuation_chars (line : Line ) -> Line :
2594
+ """Merge strings that were split across multiple lines using backslashes."""
2595
+ for leaf in line .leaves :
2596
+ if (
2597
+ leaf .type == token .STRING
2598
+ and "\\ \n " in leaf .value
2599
+ and leaf .value .lstrip (STRING_PREFIX_CHARS )[:3 ] not in {'"""' , "'''" }
2600
+ ):
2601
+ break
2602
+ else :
2603
+ return line
2604
+
2605
+ new_line = line .clone ()
2606
+ new_line .comments = line .comments
2607
+ append_leaves (new_line , line , line .leaves )
2608
+ for leaf in new_line .leaves :
2609
+ if leaf .type == token .STRING and leaf .value .lstrip (STRING_PREFIX_CHARS )[
2610
+ :3
2611
+ ] not in {'"""' , "'''" }:
2612
+ leaf .value = leaf .value .replace ("\\ \n " , "" )
2613
+
2614
+ return new_line
2615
+
2593
2616
def __merge_first_string_group (self , line : Line ) -> Tuple [Line , bool ]:
2594
2617
first_str_idx = self .__get_string_group_index (line )
2595
2618
@@ -2702,55 +2725,6 @@ def __merge_first_string_group(self, line: Line) -> Tuple[Line, bool]:
2702
2725
2703
2726
return (new_line , True )
2704
2727
2705
- @staticmethod
2706
- def __get_string_group_index (line : Line ) -> Optional [int ]:
2707
- num_of_inline_string_comments = 0
2708
- set_of_prefixes = set ()
2709
- for leaf in line .leaves :
2710
- if leaf .type == token .STRING :
2711
- prefix = get_string_prefix (leaf .value )
2712
- if prefix :
2713
- set_of_prefixes .add (prefix )
2714
-
2715
- if id (leaf ) in line .comments :
2716
- num_of_inline_string_comments += 1
2717
-
2718
- if num_of_inline_string_comments > 1 or len (set_of_prefixes ) > 1 :
2719
- return None
2720
-
2721
- for i , leaf in enumerate (line .leaves ):
2722
- if (
2723
- i + 1 < len (line .leaves )
2724
- and leaf .type == token .STRING
2725
- and line .leaves [i + 1 ].type == token .STRING
2726
- ):
2727
- return i
2728
-
2729
- return None
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
-
2754
2728
@staticmethod
2755
2729
def __remove_bad_trailing_commas (line : Line ) -> Line :
2756
2730
line_str = line_to_string (line )
@@ -2782,6 +2756,32 @@ def __remove_bad_trailing_commas(line: Line) -> Line:
2782
2756
2783
2757
return new_line
2784
2758
2759
+ @staticmethod
2760
+ def __get_string_group_index (line : Line ) -> Optional [int ]:
2761
+ num_of_inline_string_comments = 0
2762
+ set_of_prefixes = set ()
2763
+ for leaf in line .leaves :
2764
+ if leaf .type == token .STRING :
2765
+ prefix = get_string_prefix (leaf .value )
2766
+ if prefix :
2767
+ set_of_prefixes .add (prefix )
2768
+
2769
+ if id (leaf ) in line .comments :
2770
+ num_of_inline_string_comments += 1
2771
+
2772
+ if num_of_inline_string_comments > 1 or len (set_of_prefixes ) > 1 :
2773
+ return None
2774
+
2775
+ for i , leaf in enumerate (line .leaves ):
2776
+ if (
2777
+ i + 1 < len (line .leaves )
2778
+ and leaf .type == token .STRING
2779
+ and line .leaves [i + 1 ].type == token .STRING
2780
+ ):
2781
+ return i
2782
+
2783
+ return None
2784
+
2785
2785
2786
2786
class StringSplitterMixin (StringTransformerMixin ):
2787
2787
STRING_CHILD_IDX_MAP : ClassVar [Dict [int , Optional [int ]]] = {}
0 commit comments