From 8e926808aa0a79930d96f4f46a176fe3be407ce9 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 9 Dec 2023 19:25:36 -0800 Subject: [PATCH] Found another behavior change --- src/black/lines.py | 2 +- src/black/mode.py | 2 +- src/black/nodes.py | 2 +- tests/data/cases/preview_no_blank_line_before_docstring.py | 7 +++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/black/lines.py b/src/black/lines.py index 86fc2110d91..e80914de4d1 100644 --- a/src/black/lines.py +++ b/src/black/lines.py @@ -212,7 +212,7 @@ def _is_triple_quoted_string(self) -> bool: @property def is_docstring(self) -> bool: """Is the line a docstring?""" - if Preview.format_module_docstring not in self.mode: + if Preview.unify_docstring_detection not in self.mode: return self._is_triple_quoted_string return bool(self) and is_docstring(self.leaves[0], self.mode) diff --git a/src/black/mode.py b/src/black/mode.py index 55bface6365..6600f9dad75 100644 --- a/src/black/mode.py +++ b/src/black/mode.py @@ -195,7 +195,7 @@ class Preview(Enum): single_line_format_skip_with_multiple_comments = auto() long_case_block_line_splitting = auto() allow_form_feeds = auto() - format_module_docstring = auto() + unify_docstring_detection = auto() class Deprecated(UserWarning): diff --git a/src/black/nodes.py b/src/black/nodes.py index a9505db9b07..4f7a88e6ace 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -540,7 +540,7 @@ def is_docstring(leaf: Leaf, mode: Mode) -> bool: return False if ( - Preview.format_module_docstring in mode + Preview.unify_docstring_detection in mode and leaf.parent and leaf.parent.type == syms.simple_stmt and not leaf.parent.prev_sibling diff --git a/tests/data/cases/preview_no_blank_line_before_docstring.py b/tests/data/cases/preview_no_blank_line_before_docstring.py index 303035a7efb..faeaa1e46e4 100644 --- a/tests/data/cases/preview_no_blank_line_before_docstring.py +++ b/tests/data/cases/preview_no_blank_line_before_docstring.py @@ -29,6 +29,9 @@ class MultilineDocstringsAsWell: and on so many lines... """ +class SingleQuotedDocstring: + + "I'm a docstring but I don't even get triple quotes." # output @@ -57,3 +60,7 @@ class MultilineDocstringsAsWell: and on so many lines... """ + + +class SingleQuotedDocstring: + "I'm a docstring but I don't even get triple quotes."