From: Richard Si <63936253+ichard26@users.noreply.github.com> Date: Thu, 14 Jul 2022 02:26:05 +0000 (-0400) Subject: Don't (ever) put a single-char closing docstring quote on a new line (#3166) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/4f0532d6f0d030799223453195069a282e111c8b Don't (ever) put a single-char closing docstring quote on a new line (#3166) 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 --- diff --git a/CHANGES.md b/CHANGES.md index 249f775..09954f2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,9 @@ +- 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_ diff --git a/src/black/linegen.py b/src/black/linegen.py index ff54e05..20f3ac6 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -330,13 +330,14 @@ class LineGenerator(Visitor[Line]): # 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 - # 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 diff --git a/tests/data/preview/docstring_preview.py b/tests/data/preview/docstring_preview.py index 2da4cd1..292352c 100644 --- a/tests/data/preview/docstring_preview.py +++ b/tests/data/preview/docstring_preview.py @@ -42,6 +42,14 @@ def multiline_docstring_at_line_limit_with_prefix(): 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 @@ -87,3 +95,11 @@ def multiline_docstring_at_line_limit_with_prefix(): 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)."