black: Black Fails to Format Single String Longer Than Line Length Limit
Describe the bug A Python file containing a single string assignment longer than the line length limit is not reformatted.
To Reproduce
Take long_line.py:
long = "This is a long line that is longer than 88 characters. I expect Black to shorten this line length."
Run Black:
$ black ./long_line.py
All done! ✨ 🍰 ✨
1 file left unchanged.
Expected behavior
I expect black to shorten the line length to less than the length limit. One possible solution is to break on the <line length limit minus 1> character and parenthesize if it is not already inside parentheses:
long = (
"This is a long line that is longer than 88 characters. I expect Black to shorten "
"this line length."
)
Environment (please complete the following information):
$ black --version
black, version 20.8b1
OS: macOS Catalina 10.15.6
$ python --version
Python 3.8.5
Does this bug also happen on master? Yes
Additional context None
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 28 (1 by maintainers)
Links to this issue
Commits related to this issue
- fix: Update pyproject.toml https://github.com/psf/black/issues/1802 — committed to microsoft/gpt-review by dciborow a year ago
This is currently implemented under the hidden
--experimental-string-processingflag, which we’ll hopefully be able to enable soon.If wanting to specify --experimental-string-processing in pyproject.toml use this format:
Same as @Mausy5043 and @pheetah ! Docstrings are not taken into account. Can provide example if needed!|
Tried --preview and the deprecated --experimental-string-processing.
Use of the switch
--experimental-string-processingis nolonger supported and returns:Using the
--previewswitch, apart from not knowing what else is being changed, does not result in strings getting processed correctly.I have the same issue with @Mausy5043 , when I try to format with
black -l 80 --previewit works for code lines but not for strings (I have a string has 416 characters left untouched on formatting), when I use black--experimental-string-processingI get the same error.@FantasticMrFux Did you ever find the answer to this?
For anyone who still hasn’t been able to use this, I have gotten this working on my VSCode with the following
settings.jsonOr using the gui:
I think that the line length argument may be an issue with many people inputting the actual number as an additional argument after the flag rather than using the
=operator.For example, see this stackoverflow answer.
If I wanted to configure this flag on VScode should I just add
--experimental-string-processingas an argument?the below settings work .
/usr/local/bin/black --version black, version 21.9b0