-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Black Fails to Format Single String Longer Than Line Length Limit #1802
Comments
This is currently implemented under the hidden |
Confirmed that this works as expected.
|
If I wanted to configure this flag on VScode should I just add |
@Delvio I believe so IIRC. |
@ichard26 for some reason it's not working on my end, this is the config I have for the black arguments "python.formatting.blackArgs": [ Any guidance that you can provide me will be much appreciated. |
@Delvio what version of Black is installed in your environment? |
@ichard26 I was using an older version but I now upgraded to black==20.8b1, the issue persists. I even closed VSCode and opened it again (we never know) |
Ok, here's a non-exhaustive list of things to do / check:
Also it would be nice if I could get your Python Log output (Output Tab of pop-up panel and select the 'Python' output) as it may tell me why it ain't working :( I'm looking for something like this (I took this from my Visual Studio Code instance that has Black working correctly):
|
@ichard26 To avoid conflicts between workspace settings I have the same for both user and workspace settings, This is the log that I see from the python output:
|
For anyone who still hasn't been able to use this, I have gotten this working on my VSCode with the following
Or 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 For example, see this stackoverflow answer. |
If wanting to specify --experimental-string-processing in pyproject.toml use this format:
|
Strange, it works fine for me. Here's my settings.json section. "python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"70",
"--experimental-string-processing"
], -- Now the output: Before: After: |
One more QA test case: When there are no spaces in the string, test_string = "ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
another_string = "test test test test test test test test test test test test test test test test test test test test test test test test test test test test test " Before: Output: When you add spaces in the string before -- it works: -- @JelleZijlstra can you please confirm if this is intended 😅 |
Yes I confirm |
Yes, experimental string processing will not break a string if has no spaces in it. FWIW, there is a proposal to allow breaking on escaped \n as they make sense as the split point: #1467. I'd be personally happy with such a change, but I haven't looked into it quite yet. |
Hello would somebody help me how I can integrate this into vim? So executing |
the below settings work . /usr/local/bin/black --version
|
Thanks for your answer but where should I put this? Somewhere in my vimrc? |
@FantasticMrFux Did you ever find the answer to this? |
Use of the switch
Using the |
I have the same issue with @Mausy5043 , when I try to format with |
Same as @Mausy5043 and @pheetah ! Docstrings are not taken into account. Can provide example if needed!| Tried --preview and the deprecated --experimental-string-processing. |
Same as @pheetah |
Any updates on this? Why is the string not getting formatted? |
This is enabled in the |
--preview does not split the string. It leaves the file as is |
|
If you find a case where it doesn't work, please open a new issue instead of posting on this old and closed one. |
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
:Run Black:
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:Environment (please complete the following information):
OS: macOS Catalina 10.15.6
Does this bug also happen on master?
Yes
Additional context
None
The text was updated successfully, but these errors were encountered: