Skip to content

Fix unstable format involving backslash + whitespace at beginning of file#948

Merged
zsol merged 3 commits intopsf:masterfrom
Jma353:jma353-fix-922
Aug 4, 2019
Merged

Fix unstable format involving backslash + whitespace at beginning of file#948
zsol merged 3 commits intopsf:masterfrom
Jma353:jma353-fix-922

Conversation

@Jma353
Copy link
Contributor

@Jma353 Jma353 commented Jul 28, 2019

This PR fixes #922 - an unstable sort involve Python line continuation with \. The issue describes the problem pretty well.

To my knowledge, there should be no situation where Black outputs a file formatted with empty lines at the beginning. By performing this check in the format function, we fix the above issue.

NOTE: Open to feedback on this solution, threw it together pretty quickly after doing some basic debugging of how Black parses lines and whatnot. Open to feedback on it. Also, I'm pretty sure it doesn't break any invariants of the formatter, but would like feedback on that as well.

@Jma353
Copy link
Contributor Author

Jma353 commented Aug 3, 2019

Moved the check to EmptyLineTracker @zsol, this should be good for another review.

@zsol
Copy link
Collaborator

zsol commented Aug 4, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Black produced different code on the second pass of the formatter: Explicit line join in the first line

2 participants