black
black copied to clipboard
Internal Error: Cannot format - on whitespace after backslash
Describe the bug
Black generates an INTERNAL ERROR with a file that has a docstring that contains a backslash with a trailing space character. Removing the trailing space solves the issue.
To Reproduce
Create a file file.py
with the following content. Note, the 5th but last line (i.e., just above the line with other option
) contains a trailing space after the backslash!
def foo():
"""
Some description
['some option']
/
/ --- ['option b']
something[here]
\ --- ['option c'] (['d', 'e', 'f', 'g'])
\
['other option']
"""
pass
And run it with these arguments:
$ black file.py
The resulting error is:
error:
cannot format file.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug ...
.
Expected behavior
No error
Environment
- Black's version: 22.3
- OS and Python version: macos 11.6, python 3.7