]> 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:

Do not put the closing quotes in a docstring on a separate line (#3430)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Tue, 13 Dec 2022 04:56:38 +0000 (20:56 -0800)
committerGitHub <noreply@github.com>
Tue, 13 Dec 2022 04:56:38 +0000 (23:56 -0500)
Fixes #3320. Followup from #3044.

CHANGES.md
src/black/linegen.py
tests/data/preview/docstring_preview.py

index 86d44f033b8d10ab3a572cf7bf9256f27968bd24..f6040359623db9401dc29427a3dad9682270b258 100644 (file)
@@ -15,6 +15,8 @@
 <!-- Changes that affect Black's preview style -->
 
 - Fix a crash in preview style with assert + parenthesized string (#3415)
+- Do not put the closing quotes in a docstring on a separate line, even if the line is
+  too long (#3430)
 
 ### Configuration
 
index 219495e9a5e12771ce8837ddcae4c60c24018b73..644824a3c861c34d45ce7befc73a783ea7d6dc2b 100644 (file)
@@ -389,19 +389,18 @@ class LineGenerator(Visitor[Line]):
                 # We need to find the length of the last line of the docstring
                 # to find if we can add the closing quotes to the line without
                 # exceeding the maximum line length.
-                # If docstring is one line, then we need to add the length
-                # of the indent, prefix, and starting quotes. Ending quotes are
-                # handled later.
+                # If docstring is one line, we don't put the closing quotes on a
+                # separate line because it looks ugly (#3320).
                 lines = docstring.splitlines()
                 last_line_length = len(lines[-1]) if docstring else 0
 
-                if len(lines) == 1:
-                    last_line_length += len(indent) + len(prefix) + quote_len
-
                 # If adding closing quotes would cause the last line to exceed
                 # the maximum line length then put a line break before the
                 # closing quotes
-                if last_line_length + quote_len > self.mode.line_length:
+                if (
+                    len(lines) > 1
+                    and last_line_length + quote_len > self.mode.line_length
+                ):
                     leaf.value = prefix + quote + docstring + "\n" + indent + quote
                 else:
                     leaf.value = prefix + quote + docstring + quote
index 292352c82f328b8a4b32731cca1b94949dbaa8af..ff4819acb67a876c50377bcc535f179332c6aed7 100644 (file)
@@ -54,13 +54,11 @@ def single_quote_docstring_over_line_limit2():
 
 
 def docstring_almost_at_line_limit():
-    """long docstring.................................................................
-    """
+    """long docstring................................................................."""
 
 
 def docstring_almost_at_line_limit_with_prefix():
-    f"""long docstring................................................................
-    """
+    f"""long docstring................................................................"""
 
 
 def mulitline_docstring_almost_at_line_limit():