Fix crash on docstrings ending with "\ " (#2142)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
97c24664c5
commit
557b54aa60
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#### _Black_
|
#### _Black_
|
||||||
|
|
||||||
|
- Fix crash on docstrings ending with "\ ". (#2142)
|
||||||
|
|
||||||
- Reflect the `--skip-magic-trailing-comma` and `--experimental-string-processing` flags
|
- Reflect the `--skip-magic-trailing-comma` and `--experimental-string-processing` flags
|
||||||
in the name of the cache file. Without this fix, changes in these flags would not take
|
in the name of the cache file. Without this fix, changes in these flags would not take
|
||||||
effect if the cache had already been populated. (#2131)
|
effect if the cache had already been populated. (#2131)
|
||||||
|
@ -2186,7 +2186,13 @@ def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
|
|||||||
if docstring[0] == quote_char:
|
if docstring[0] == quote_char:
|
||||||
docstring = " " + docstring
|
docstring = " " + docstring
|
||||||
if docstring[-1] == quote_char:
|
if docstring[-1] == quote_char:
|
||||||
docstring = docstring + " "
|
docstring += " "
|
||||||
|
if docstring[-1] == "\\":
|
||||||
|
backslash_count = len(docstring) - len(docstring.rstrip("\\"))
|
||||||
|
if backslash_count % 2:
|
||||||
|
# Odd number of tailing backslashes, add some padding to
|
||||||
|
# avoid escaping the closing string quote.
|
||||||
|
docstring += " "
|
||||||
else:
|
else:
|
||||||
# Add some padding if the docstring is empty.
|
# Add some padding if the docstring is empty.
|
||||||
docstring = " "
|
docstring = " "
|
||||||
|
@ -158,6 +158,22 @@ def docstring_with_inline_tabs_and_tab_indentation():
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def backslash_space():
|
||||||
|
"""\ """
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_backslash_1():
|
||||||
|
'''
|
||||||
|
hey\there\
|
||||||
|
\ '''
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_backslash_2():
|
||||||
|
'''
|
||||||
|
hey there \ '''
|
||||||
|
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
class MyClass:
|
class MyClass:
|
||||||
@ -316,3 +332,18 @@ def docstring_with_inline_tabs_and_tab_indentation():
|
|||||||
line ends with some tabs
|
line ends with some tabs
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def backslash_space():
|
||||||
|
"""\ """
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_backslash_1():
|
||||||
|
"""
|
||||||
|
hey\there\
|
||||||
|
\ """
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_backslash_2():
|
||||||
|
"""
|
||||||
|
hey there \ """
|
||||||
|
Loading…
Reference in New Issue
Block a user