|
688 | 688 | and bool(current_line.leaves) |
689 | 689 | and "\f\n" in current_line.leaves[0].prefix |
690 | 690 | ) |
691 | | -@@ -618,7 +639,7 @@ class EmptyLineTracker: |
| 691 | +@@ -611,6 +632,8 @@ class EmptyLineTracker: |
| 692 | + or current_line.is_def |
| 693 | + ): |
| 694 | + return False |
| 695 | ++ if previous_block.original_line.depth: |
| 696 | ++ return False |
| 697 | + while previous_block := previous_block.previous_block: |
| 698 | + if not previous_block.original_line.is_comment: |
| 699 | + return False |
| 700 | +@@ -618,7 +641,7 @@ class EmptyLineTracker: |
692 | 701 |
|
693 | 702 | def _maybe_empty_lines(self, current_line: Line) -> tuple[int, int]: |
694 | 703 | max_allowed = 1 |
|
697 | 706 | max_allowed = 1 if self.mode.is_pyi else 2 |
698 | 707 |
|
699 | 708 | if current_line.leaves: |
700 | | -@@ -635,7 +656,7 @@ class EmptyLineTracker: |
| 709 | +@@ -635,7 +658,7 @@ class EmptyLineTracker: |
701 | 710 |
|
702 | 711 | # Mutate self.previous_defs, remainder of this function should be pure |
703 | 712 | previous_def = None |
|
706 | 715 | previous_def = self.previous_defs.pop() |
707 | 716 | if current_line.is_def or current_line.is_class: |
708 | 717 | self.previous_defs.append(current_line) |
709 | | -@@ -692,8 +713,8 @@ class EmptyLineTracker: |
| 718 | +@@ -692,8 +715,8 @@ class EmptyLineTracker: |
710 | 719 |
|
711 | 720 | if ( |
712 | 721 | self.previous_line.is_import |
|
717 | 726 | and not current_line.is_import |
718 | 727 | and not current_line.is_fmt_pass_converted(first_leaf_matches=is_import) |
719 | 728 | and Preview.always_one_newline_after_import in self.mode |
720 | | -@@ -701,10 +722,25 @@ class EmptyLineTracker: |
| 729 | +@@ -701,10 +724,25 @@ class EmptyLineTracker: |
721 | 730 | return 1, 0 |
722 | 731 |
|
723 | 732 | if ( |
|
745 | 754 | ): |
746 | 755 | return (before or 1), 0 |
747 | 756 |
|
748 | | -@@ -721,8 +757,9 @@ class EmptyLineTracker: |
| 757 | +@@ -721,8 +759,9 @@ class EmptyLineTracker: |
749 | 758 | return 0, 1 |
750 | 759 | return 0, 0 |
751 | 760 |
|
|
757 | 766 | ): |
758 | 767 | if self.mode.is_pyi: |
759 | 768 | return 0, 0 |
760 | | -@@ -731,7 +768,7 @@ class EmptyLineTracker: |
| 769 | +@@ -731,7 +770,7 @@ class EmptyLineTracker: |
761 | 770 | comment_to_add_newlines: LinesBlock | None = None |
762 | 771 | if ( |
763 | 772 | self.previous_line.is_comment |
|
766 | 775 | and before == 0 |
767 | 776 | ): |
768 | 777 | slc = self.semantic_leading_comment |
769 | | -@@ -748,9 +785,9 @@ class EmptyLineTracker: |
| 778 | +@@ -748,9 +787,9 @@ class EmptyLineTracker: |
770 | 779 |
|
771 | 780 | if self.mode.is_pyi: |
772 | 781 | if current_line.is_class or self.previous_line.is_class: |
|
778 | 787 | newlines = 1 |
779 | 788 | elif current_line.is_stub_class and self.previous_line.is_stub_class: |
780 | 789 | # No blank line between classes with an empty body |
781 | | -@@ -779,7 +816,11 @@ class EmptyLineTracker: |
| 790 | +@@ -779,7 +818,11 @@ class EmptyLineTracker: |
782 | 791 | newlines = 1 if current_line.depth else 2 |
783 | 792 | # If a user has left no space after a dummy implementation, don't insert |
784 | 793 | # new lines. This is useful for instance for @overload or Protocols. |
|
791 | 800 | newlines = 0 |
792 | 801 | if comment_to_add_newlines is not None: |
793 | 802 | previous_block = comment_to_add_newlines.previous_block |
794 | | -@@ -1054,7 +1095,7 @@ def can_omit_invisible_parens( |
| 803 | +@@ -1054,7 +1097,7 @@ def can_omit_invisible_parens( |
795 | 804 | def _can_omit_opening_paren(line: Line, *, first: Leaf, line_length: int) -> bool: |
796 | 805 | """See `can_omit_invisible_parens`.""" |
797 | 806 | remainder = False |
|
800 | 809 | _index = -1 |
801 | 810 | for _index, leaf, leaf_length in line.enumerate_with_length(): |
802 | 811 | if leaf.type in CLOSING_BRACKETS and leaf.opening_bracket is first: |
803 | | -@@ -1078,7 +1119,7 @@ def _can_omit_opening_paren(line: Line, |
| 812 | +@@ -1078,7 +1121,7 @@ def _can_omit_opening_paren(line: Line, |
804 | 813 |
|
805 | 814 | def _can_omit_closing_paren(line: Line, *, last: Leaf, line_length: int) -> bool: |
806 | 815 | """See `can_omit_invisible_parens`.""" |
|
0 commit comments