]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Remove blank lines before class docstring (#3692)
authorJonathan Berthias <jvberthias@gmail.com>
Thu, 18 May 2023 23:57:17 +0000 (01:57 +0200)
committerGitHub <noreply@github.com>
Thu, 18 May 2023 23:57:17 +0000 (16:57 -0700)
CHANGES.md
src/black/lines.py
src/black/mode.py
tests/data/preview/no_blank_line_before_docstring.py [new file with mode: 0644]

index a1bc7d590205ebf71a83aaeeac69d7af66b2948a..6a9923f8d8d381b8e4682581a3ae35f2de6c8ebf 100644 (file)
@@ -16,6 +16,7 @@
 
 - Implicitly concatenated strings used as function args are no longer wrapped inside
   parentheses (#3640)
 
 - Implicitly concatenated strings used as function args are no longer wrapped inside
   parentheses (#3640)
+- Remove blank lines between a class definition and its docstring (#3692)
 
 ### Configuration
 
 
 ### Configuration
 
index 9d33bfa10b434e4075e2124cd41f586512762ffe..daf0444d24e9a7d57c86f290344323fc7397f775 100644 (file)
@@ -634,6 +634,8 @@ class EmptyLineTracker:
             and self.previous_line.is_class
             and current_line.is_triple_quoted_string
         ):
             and self.previous_line.is_class
             and current_line.is_triple_quoted_string
         ):
+            if Preview.no_blank_line_before_class_docstring in current_line.mode:
+                return 0, 1
             return before, 1
 
         if self.previous_line and self.previous_line.opens_block:
             return before, 1
 
         if self.previous_line and self.previous_line.opens_block:
index 3e37a588e522d5c594c916f874244951526f759b..a5841edb30a791cd17d8ad810542adbd7640e617 100644 (file)
@@ -158,6 +158,7 @@ class Preview(Enum):
     hex_codes_in_unicode_sequences = auto()
     improved_async_statements_handling = auto()
     multiline_string_handling = auto()
     hex_codes_in_unicode_sequences = auto()
     improved_async_statements_handling = auto()
     multiline_string_handling = auto()
+    no_blank_line_before_class_docstring = auto()
     prefer_splitting_right_hand_side_of_assignments = auto()
     # NOTE: string_processing requires wrap_long_dict_values_in_parens
     # for https://github.com/psf/black/issues/3117 to be fixed.
     prefer_splitting_right_hand_side_of_assignments = auto()
     # NOTE: string_processing requires wrap_long_dict_values_in_parens
     # for https://github.com/psf/black/issues/3117 to be fixed.
diff --git a/tests/data/preview/no_blank_line_before_docstring.py b/tests/data/preview/no_blank_line_before_docstring.py
new file mode 100644 (file)
index 0000000..a37362d
--- /dev/null
@@ -0,0 +1,58 @@
+def line_before_docstring():
+
+    """Please move me up"""
+
+
+class LineBeforeDocstring:
+
+    """Please move me up"""
+
+
+class EvenIfThereIsAMethodAfter:
+
+    """I'm the docstring"""
+    def method(self):
+        pass
+
+
+class TwoLinesBeforeDocstring:
+
+
+    """I want to be treated the same as if I were closer"""
+
+
+class MultilineDocstringsAsWell:
+
+    """I'm so far
+
+    and on so many lines...
+    """
+
+
+# output
+
+
+def line_before_docstring():
+    """Please move me up"""
+
+
+class LineBeforeDocstring:
+    """Please move me up"""
+
+
+class EvenIfThereIsAMethodAfter:
+    """I'm the docstring"""
+
+    def method(self):
+        pass
+
+
+class TwoLinesBeforeDocstring:
+    """I want to be treated the same as if I were closer"""
+
+
+class MultilineDocstringsAsWell:
+    """I'm so far
+
+    and on so many lines...
+    """