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

Treat raw strings like other docstrings (#3947)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Mon, 16 Oct 2023 17:51:51 +0000 (10:51 -0700)
committerGitHub <noreply@github.com>
Mon, 16 Oct 2023 17:51:51 +0000 (10:51 -0700)
Fixes #3944

CHANGES.md
src/black/lines.py
src/black/mode.py
tests/data/raw_docstring.py [new file with mode: 0644]

index d1c4a075c325030cf53f521c58cadee8274f5ff4..1f6a008d643cc6fe9159b7861147f10e85511a03 100644 (file)
@@ -21,6 +21,7 @@
   multiple lines (#3899)
 - Magic trailing commas are now respected in return types. (#3916)
 - Require one empty line after module-level docstrings. (#3932)
+- Treat raw triple-quoted strings as docstrings (#3947)
 
 ### Configuration
 
index 14754d7532ff4827d2773ae023953a15f8722a07..48fde88820853deec0e5b6405a8b4bf116bf9fe4 100644 (file)
@@ -193,11 +193,16 @@ class Line:
     @property
     def is_triple_quoted_string(self) -> bool:
         """Is the line a triple quoted string?"""
-        return (
-            bool(self)
-            and self.leaves[0].type == token.STRING
-            and self.leaves[0].value.startswith(('"""', "'''"))
-        )
+        if not self or self.leaves[0].type != token.STRING:
+            return False
+        value = self.leaves[0].value
+        if value.startswith(('"""', "'''")):
+            return True
+        if Preview.accept_raw_docstrings in self.mode and value.startswith(
+            ("r'''", 'r"""', "R'''", 'R"""')
+        ):
+            return True
+        return False
 
     @property
     def opens_block(self) -> bool:
index a57fa373568dcb0c8ede83db0a87486b2cf3e33f..309f22dae94b61595bdc2e9d713ee887e3b75f27 100644 (file)
@@ -188,6 +188,7 @@ class Preview(Enum):
     dummy_implementations = auto()
     walrus_subscript = auto()
     module_docstring_newlines = auto()
+    accept_raw_docstrings = auto()
     fix_power_op_line_length = auto()
 
 
diff --git a/tests/data/raw_docstring.py b/tests/data/raw_docstring.py
new file mode 100644 (file)
index 0000000..751fd32
--- /dev/null
@@ -0,0 +1,32 @@
+# flags: --preview --skip-string-normalization
+class C:
+
+    r"""Raw"""
+
+def f():
+
+    r"""Raw"""
+
+class SingleQuotes:
+
+
+    r'''Raw'''
+
+class UpperCaseR:
+    R"""Raw"""
+
+# output
+class C:
+    r"""Raw"""
+
+
+def f():
+    r"""Raw"""
+
+
+class SingleQuotes:
+    r'''Raw'''
+
+
+class UpperCaseR:
+    R"""Raw"""