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

Don't (ever) put a single-char closing docstring quote on a new line (#3166)
authorRichard Si <63936253+ichard26@users.noreply.github.com>
Thu, 14 Jul 2022 02:26:05 +0000 (22:26 -0400)
committerGitHub <noreply@github.com>
Thu, 14 Jul 2022 02:26:05 +0000 (22:26 -0400)
Doing so is invalid. Note this only fixes the preview style since the
logic putting closing docstring quotes on their own line if they violate
the line length limit is quite new.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
CHANGES.md
src/black/linegen.py
tests/data/preview/docstring_preview.py

index 249f7752beacbe53630f12351fc2489675e5a1cd..09954f2b7382a3649f29454819620dbbe9166fdb 100644 (file)
@@ -17,6 +17,9 @@
 
 <!-- Changes that affect Black's preview style -->
 
 
 <!-- Changes that affect Black's preview style -->
 
+- Single-character closing docstring quotes are no longer moved to their own line as
+  this is invalid. This was a bug introduced in version 22.6.0. (#3166)
+
 ### _Blackd_
 
 <!-- Changes to blackd -->
 ### _Blackd_
 
 <!-- Changes to blackd -->
index ff54e05c4e6299d1bd2a456473a169839a03b43a..20f3ac6fffb1524b014f1dd43435630c073c6b85 100644 (file)
@@ -330,13 +330,14 @@ class LineGenerator(Visitor[Line]):
             # We could enforce triple quotes at this point.
             quote = quote_char * quote_len
 
             # We could enforce triple quotes at this point.
             quote = quote_char * quote_len
 
-            if Preview.long_docstring_quotes_on_newline in self.mode:
+            # It's invalid to put closing single-character quotes on a new line.
+            if Preview.long_docstring_quotes_on_newline in self.mode and quote_len == 3:
                 # 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
                 # 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 quote are
-                # handled later
+                # of the indent, prefix, and starting quotes. Ending quotes are
+                # handled later.
                 lines = docstring.splitlines()
                 last_line_length = len(lines[-1]) if docstring else 0
 
                 lines = docstring.splitlines()
                 last_line_length = len(lines[-1]) if docstring else 0
 
index 2da4cd1acdb305215335ae6d3be1cf1f7aa7c19d..292352c82f328b8a4b32731cca1b94949dbaa8af 100644 (file)
@@ -42,6 +42,14 @@ def multiline_docstring_at_line_limit_with_prefix():
     second line----------------------------------------------------------------------"""
 
 
     second line----------------------------------------------------------------------"""
 
 
+def single_quote_docstring_over_line_limit():
+    "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
+
+
+def single_quote_docstring_over_line_limit2():
+    'We do not want to put the closing quote on a new line as that is invalid (see GH-3141).'
+
+
 # output
 
 
 # output
 
 
@@ -87,3 +95,11 @@ def multiline_docstring_at_line_limit_with_prefix():
     f"""first line----------------------------------------------------------------------
 
     second line----------------------------------------------------------------------"""
     f"""first line----------------------------------------------------------------------
 
     second line----------------------------------------------------------------------"""
+
+
+def single_quote_docstring_over_line_limit():
+    "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
+
+
+def single_quote_docstring_over_line_limit2():
+    "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."