Skip to content

Commit 3974630

Browse files
committed
Keep compability with stdlib tokenize.py changes
python/cpython@c4ef489 is not yet part of any release of Python but has been backported to all versions in Git (includeing 2.7!). It causes the tokenize.py module to emit a synthetic NEWLINE token for files that do not in fact end with a newline, which confuses pycodestyle's checks for blank lines at the end of a file. Fortunately the synthetic NEWLINE tokens are easy to detect (the token text is ""). Fixes #786
1 parent c3d2cbd commit 3974630

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pycodestyle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ def trailing_blank_lines(physical_line, lines, line_number, total_lines):
258258
"""
259259
if line_number == total_lines:
260260
stripped_last_line = physical_line.rstrip()
261-
if not stripped_last_line:
261+
if physical_line and not stripped_last_line:
262262
return 0, "W391 blank line at end of file"
263263
if stripped_last_line == physical_line:
264-
return len(physical_line), "W292 no newline at end of file"
264+
return len(lines[-1]), "W292 no newline at end of file"
265265

266266

267267
@register_check

0 commit comments

Comments
 (0)