-
-
Notifications
You must be signed in to change notification settings - Fork 30.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
3.12: tokenize adds a newline when it is not there #105259
Comments
@lysnikolaou can you take a look at this? I think this is due to this line: Line 1309 in e6373c0
in combination with this line: cpython/Python/Python-tokenize.c Line 249 in e6373c0
But the real question is what is going to break if we cover the first line with |
@lysnikolaou The problem is that we are always adding a new line at the end of the line buffer so we cannot distinguish if the last one is there for real or not (also, we always hardcode |
Do we? I thought you had removed this in #104850, but I guess I misunderstood that PR. I'll have a look. |
That was "reverted" because apparently that was required to keep backward compatibility IIRC. But this is also a different kind of "new line": the tokenize module needs new lines at the end of every logical line to correctly emit the last tokens. Just comment out this part and see what fails (locations of last tokens are wrong as well as the some implicit dedents are missing): Line 1309 in e6373c0
Notice that just removing that is not enough to fix this: we would also need to emit the last artificial newline if the input doesn't contain it. |
@Yhg1s can you wait until we fix this for the release? |
Yeah, I can wait. |
… NEWLINE tokens (pythonGH-105364) (cherry picked from commit c0a6ed3) Co-authored-by: Pablo Galindo Salgado <[email protected]>
@asottile can you confirm this fixes it? |
yep looks fixed -- this is the only outstanding breaking change I'm encountering: #105390 |
Bug report
tokenize adds a concrete newline character when it is not present. this breaks any sort of roundtrip source generation and pycodestyle's end-of-file checker
here's an example of a file containing a single byte (generated via
echo -n 1 > t.py
)Your environment
cc @pablogsal
Linked PRs
The text was updated successfully, but these errors were encountered: