|
780 | 780 | or self.bracket_tracker.any_open_for_or_lambda()
|
781 | 781 | ):
|
782 | 782 | if self.is_comment:
|
783 |
| -@@ -262,7 +278,7 @@ class Line: |
| 783 | +@@ -262,7 +278,14 @@ class Line: |
784 | 784 | return True
|
785 | 785 | return False
|
786 | 786 |
|
787 | 787 | - def contains_uncollapsable_type_comments(self) -> bool:
|
| 788 | ++ def contains_pragma_comments(self) -> bool: |
| 789 | ++ for comments in self.comments.values(): |
| 790 | ++ for comment in comments: |
| 791 | ++ if is_pragma_comment(comment, self.mode): |
| 792 | ++ return True |
| 793 | ++ return False |
| 794 | ++ |
788 | 795 | + def contains_uncollapsable_pragma_comments(self) -> bool:
|
789 | 796 | ignored_ids = set()
|
790 | 797 | try:
|
791 | 798 | last_leaf = self.leaves[-1]
|
792 |
| -@@ -287,11 +303,9 @@ class Line: |
| 799 | +@@ -287,11 +310,9 @@ class Line: |
793 | 800 | comment_seen = False
|
794 | 801 | for leaf_id, comments in self.comments.items():
|
795 | 802 | for comment in comments:
|
|
804 | 811 | return True
|
805 | 812 |
|
806 | 813 | comment_seen = True
|
807 |
| -@@ -326,7 +340,7 @@ class Line: |
| 814 | +@@ -326,7 +347,7 @@ class Line: |
808 | 815 | # line.
|
809 | 816 | for node in self.leaves[-2:]:
|
810 | 817 | for comment in self.comments.get(id(node), []):
|
|
813 | 820 | return True
|
814 | 821 |
|
815 | 822 | return False
|
816 |
| -@@ -481,7 +495,7 @@ class Line: |
| 823 | +@@ -481,7 +502,7 @@ class Line: |
817 | 824 | if not self:
|
818 | 825 | return "\n"
|
819 | 826 |
|
|
822 | 829 | leaves = iter(self.leaves)
|
823 | 830 | first = next(leaves)
|
824 | 831 | res = f"{first.prefix}{indent}{first.value}"
|
825 |
| -@@ -553,7 +567,7 @@ class EmptyLineTracker: |
| 832 | +@@ -553,7 +574,7 @@ class EmptyLineTracker: |
826 | 833 | lines (two on module-level).
|
827 | 834 | """
|
828 | 835 | form_feed = (
|
|
831 | 838 | and bool(current_line.leaves)
|
832 | 839 | and "\f\n" in current_line.leaves[0].prefix
|
833 | 840 | )
|
834 |
| -@@ -598,7 +612,7 @@ class EmptyLineTracker: |
| 841 | +@@ -598,7 +619,7 @@ class EmptyLineTracker: |
835 | 842 |
|
836 | 843 | def _maybe_empty_lines(self, current_line: Line) -> tuple[int, int]: # noqa: C901
|
837 | 844 | max_allowed = 1
|
|
840 | 847 | max_allowed = 1 if self.mode.is_pyi else 2
|
841 | 848 |
|
842 | 849 | if current_line.leaves:
|
843 |
| -@@ -615,7 +629,7 @@ class EmptyLineTracker: |
| 850 | +@@ -615,7 +636,7 @@ class EmptyLineTracker: |
844 | 851 |
|
845 | 852 | # Mutate self.previous_defs, remainder of this function should be pure
|
846 | 853 | previous_def = None
|
|
849 | 856 | previous_def = self.previous_defs.pop()
|
850 | 857 | if current_line.is_def or current_line.is_class:
|
851 | 858 | self.previous_defs.append(current_line)
|
852 |
| -@@ -671,10 +685,25 @@ class EmptyLineTracker: |
| 859 | +@@ -671,10 +692,25 @@ class EmptyLineTracker: |
853 | 860 | )
|
854 | 861 |
|
855 | 862 | if (
|
|
877 | 884 | ):
|
878 | 885 | return (before or 1), 0
|
879 | 886 |
|
880 |
| -@@ -691,8 +720,9 @@ class EmptyLineTracker: |
| 887 | +@@ -691,8 +727,9 @@ class EmptyLineTracker: |
881 | 888 | return 0, 1
|
882 | 889 | return 0, 0
|
883 | 890 |
|
|
889 | 896 | ):
|
890 | 897 | if self.mode.is_pyi:
|
891 | 898 | return 0, 0
|
892 |
| -@@ -701,7 +731,7 @@ class EmptyLineTracker: |
| 899 | +@@ -701,7 +738,7 @@ class EmptyLineTracker: |
893 | 900 | comment_to_add_newlines: Optional[LinesBlock] = None
|
894 | 901 | if (
|
895 | 902 | self.previous_line.is_comment
|
|
898 | 905 | and before == 0
|
899 | 906 | ):
|
900 | 907 | slc = self.semantic_leading_comment
|
901 |
| -@@ -718,9 +748,9 @@ class EmptyLineTracker: |
| 908 | +@@ -718,9 +755,9 @@ class EmptyLineTracker: |
902 | 909 |
|
903 | 910 | if self.mode.is_pyi:
|
904 | 911 | if current_line.is_class or self.previous_line.is_class:
|
|
910 | 917 | newlines = 1
|
911 | 918 | elif current_line.is_stub_class and self.previous_line.is_stub_class:
|
912 | 919 | # No blank line between classes with an empty body
|
913 |
| -@@ -749,7 +779,11 @@ class EmptyLineTracker: |
| 920 | +@@ -749,7 +786,11 @@ class EmptyLineTracker: |
914 | 921 | newlines = 1 if current_line.depth else 2
|
915 | 922 | # If a user has left no space after a dummy implementation, don't insert
|
916 | 923 | # new lines. This is useful for instance for @overload or Protocols.
|
|
923 | 930 | newlines = 0
|
924 | 931 | if comment_to_add_newlines is not None:
|
925 | 932 | previous_block = comment_to_add_newlines.previous_block
|
926 |
| -@@ -1020,7 +1054,7 @@ def can_omit_invisible_parens( |
| 933 | +@@ -1020,7 +1061,7 @@ def can_omit_invisible_parens( |
927 | 934 | def _can_omit_opening_paren(line: Line, *, first: Leaf, line_length: int) -> bool:
|
928 | 935 | """See `can_omit_invisible_parens`."""
|
929 | 936 | remainder = False
|
|
932 | 939 | _index = -1
|
933 | 940 | for _index, leaf, leaf_length in line.enumerate_with_length():
|
934 | 941 | if leaf.type in CLOSING_BRACKETS and leaf.opening_bracket is first:
|
935 |
| -@@ -1044,7 +1078,7 @@ def _can_omit_opening_paren(line: Line, |
| 942 | +@@ -1044,7 +1085,7 @@ def _can_omit_opening_paren(line: Line, |
936 | 943 |
|
937 | 944 | def _can_omit_closing_paren(line: Line, *, last: Leaf, line_length: int) -> bool:
|
938 | 945 | """See `can_omit_invisible_parens`."""
|
|
0 commit comments