-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
using black as formatter will need two runs on four+ newlines #11001
Comments
The issue seems to be with this line where we parse diffs: We should likely get rid of the |
import numpy as np
def test():
return 0 sorry for the confusion - @ichard26 is absolutely right - i got confused about what was exepcted and what wasn't yet the other issues remain. |
@hochreitercorpuls that is expected behaviour as top level functions (and classes too) are always surrounded by two empty lines (unless it's at the start or the end of the file) by Black. |
I've just found that the VSCode-black integration is not adding a newline to the end of a file that does not have one. I suspect this is the same problem as this, based on other similar problems being duplicated to this issue. Manually adding the missing line is not removed when saving, suggesting that it's the same issue as this. With the same binary, As a workaround for this, I can set Python files to always insert the final newline in my setings.json. "[python]": {
"files.insertFinalNewline": true
}, although I'm not currently having problems with excess final newlines being removed, I assume setting As a quick sanity check, I confirmed that the problem happens in both |
@TBBle it's an issue on Black's side not VS Code's -> psf/black#1662 |
Ah, thank you. Sorry for the noise. |
This should be working better with the formatter extension, please try that. This feature is moved to the extension, and future features and bugs will be addressed there: https://github.com/microsoft/vscode-black-formatter |
Environment data
"python.jediEnabled"
set to; more info How to update the language server to the latest stable version #3977): disabledExpected behaviour
given a python file like this (with 4+ lines between import statements and the first function definition):
I'd expect running black inside VS Code to reformat the given file would lead to a file like this:
with two newlines after the import statements. Running
black link_to_file.py
manually in a conda shell does exactly what is expected.Actual behaviour
Actually a first run of black leads to three newlines inbetween imports and first definition
and a second run is needed to get to the expectet result.
Steps to reproduce:
see above
The text was updated successfully, but these errors were encountered: