Produce equivalent code for docstrings containing backslash followed by whitespace(s) before newline (#4008)
Fixes #3727
This commit is contained in:
parent
ddfecf06c1
commit
e50110353a
@ -8,7 +8,8 @@
|
||||
|
||||
### Stable style
|
||||
|
||||
<!-- Changes that affect Black's stable style -->
|
||||
- Fix a crash when whitespace(s) followed a backslash before newline in a docstring
|
||||
(#4008)
|
||||
|
||||
### Preview style
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
Generating lines of code.
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
from dataclasses import replace
|
||||
from enum import Enum, auto
|
||||
@ -420,7 +421,7 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
|
||||
if Preview.hex_codes_in_unicode_sequences in self.mode:
|
||||
normalize_unicode_escape_sequences(leaf)
|
||||
|
||||
if is_docstring(leaf) and "\\\n" not in leaf.value:
|
||||
if is_docstring(leaf) and not re.search(r"\\\s*\n", leaf.value):
|
||||
# We're ignoring docstrings with backslash newline escapes because changing
|
||||
# indentation of those changes the AST representation of the code.
|
||||
if self.mode.string_normalization:
|
||||
|
@ -221,6 +221,12 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||
'''
|
||||
|
||||
|
||||
def foo():
|
||||
"""
|
||||
Docstring with a backslash followed by a space\
|
||||
and then another line
|
||||
"""
|
||||
|
||||
# output
|
||||
|
||||
class MyClass:
|
||||
@ -442,3 +448,10 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||
|
||||
<text here, since without another non-empty line black is stable>
|
||||
"""
|
||||
|
||||
|
||||
def foo():
|
||||
"""
|
||||
Docstring with a backslash followed by a space\
|
||||
and then another line
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user