| 1 | From 397463014fda3cdefe8d6c9d117ae16d878dc494 Mon Sep 17 00:00:00 2001
|
| 2 | From: Michael Hudson-Doyle <[email protected]>
|
| 3 | Date: Tue, 25 Sep 2018 14:58:57 +1200
|
| 4 | Subject: [PATCH] Keep compability with stdlib tokenize.py changes
|
| 5 |
|
| 6 | https://github.com/python/cpython/commit/c4ef4896eac86a6759901c8546e26de4695a1389
|
| 7 | is not yet part of any release of Python but has been backported to all
|
| 8 | versions in Git (includeing 2.7!). It causes the tokenize.py module to
|
| 9 | emit a synthetic NEWLINE token for files that do not in fact end with a
|
| 10 | newline, which confuses pycodestyle's checks for blank lines at the end
|
| 11 | of a file. Fortunately the synthetic NEWLINE tokens are easy to detect
|
| 12 | (the token text is "").
|
| 13 |
|
| 14 | Fixes #786
|
| 15 | ---
|
| 16 | pycodestyle.py | 4 ++--
|
| 17 | 1 file changed, 2 insertions(+), 2 deletions(-)
|
| 18 |
|
| 19 | diff --git a/pycodestyle.py b/pycodestyle.py
|
| 20 | index 0d725d27..fbc3dca3 100755
|
| 21 | |
| 22 | |
| 23 | @@ -258,10 +258,10 @@ def trailing_blank_lines(physical_line, lines, line_number, total_lines):
|
| 24 | """
|
| 25 | if line_number == total_lines:
|
| 26 | stripped_last_line = physical_line.rstrip()
|
| 27 | - if not stripped_last_line:
|
| 28 | + if physical_line and not stripped_last_line:
|
| 29 | return 0, "W391 blank line at end of file"
|
| 30 | if stripped_last_line == physical_line:
|
| 31 | - return len(physical_line), "W292 no newline at end of file"
|
| 32 | + return len(lines[-1]), "W292 no newline at end of file"
|
| 33 |
|
| 34 |
|
| 35 | @register_check
|