You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Trailing whitespace changes are made outside of --lines #613
It appears to be a problem in the PyTreeVisitor implmentation. When building the uwlines for the file, for example with_trailing_whitespace(): will lose the trailing whitespace as part of the Visit_suite method:
defVisit_suite(self, node): # pylint: disable=invalid-name# A 'suite' starts a new indentation level in Python.self._cur_depth+=1self._StartNewLine()
self.DefaultNodeVisit(node)
self._cur_depth-=1
Here, node.children[ 0 ] will have a value of \n and a prefix of the trailing whitespace contents, but those trailing whitespace contents will not be added to the _cur_unwrapped_line before finalizing it in _StartNewLine().
I've created a fork (PR 1102) that fixes this bug, but it needs extensive testing as making this right is quite difficult. It still wouldn't fix the test case in the initial post, as the whitespace before line 4 will be changed, but at least majority of the issue is fixed.
Activity
braineo commentedon Jan 2, 2019
I also ran into this issue.
wwade commentedon Mar 24, 2020
It appears to be a problem in the
PyTreeVisitorimplmentation. When building theuwlinesfor the file, for examplewith_trailing_whitespace():will lose the trailing whitespace as part of theVisit_suitemethod:Here,
node.children[ 0 ]will have a value of\nand a prefix of the trailing whitespace contents, but those trailing whitespace contents will not be added to the_cur_unwrapped_linebefore finalizing it in_StartNewLine().SkyeNygaard commentedon Nov 4, 2022
This is still an issue and it is preventing me from using yapf on my projects.
limwz01 commentedon Jun 5, 2023
@SkyeNygaard @braineo @dmytrokyrychuk
I've created a fork (PR 1102) that fixes this bug, but it needs extensive testing as making this right is quite difficult. It still wouldn't fix the test case in the initial post, as the whitespace before line 4 will be changed, but at least majority of the issue is fixed.
For convenience, here's the patch: yapf_restrict_lines.diff.txt