-
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
All-whitespace files do not get their newlines removed #2382
Comments
So @JelleZijlstra the expected behavior is for all-whitespace files to be truncated instead of being left unmodified? Makes sense. So it's actually |
I'm open to persuasion otherwise, but it makes sense to me to truncate such files to either empty or a single newline. I suppose it doesn't make a huge difference in practice. |
I think a single newline is the right choice here given that under unix a trailing newline indicates text files. |
From @akaihola in #779:
In akaihola/darker#164 (comment) we noticed that
format_str()
gives different results for some files than runningblack
from the command line orblack.main(..., standalone_mode=False)
. This should probably be fixed before makingformat_str()
an officially public Python API.Consider this test script
compare_black.py
:If you create a valid Python source code file with just a few newlines:
and reformat it using the above script:
You see that
format_str()
removes those blank lines whilemain()
andblack
leave the file untouched.I haven't tried to found other cases where these outputs don't match. I wonder if it only happens to all-whitespace files. Edit: Yes, only with all-whitespace files.
Originally posted by @akaihola in #779 (comment)
The text was updated successfully, but these errors were encountered: