diff options
author | Michael Hudson-Doyle <michael.hudson@canonical.com> | 2018-09-25 14:58:57 +1200 |
---|---|---|
committer | Michael Hudson-Doyle <michael.hudson@canonical.com> | 2018-09-25 15:01:27 +1200 |
commit | 397463014fda3cdefe8d6c9d117ae16d878dc494 (patch) | |
tree | bc2a51ce36141a1b7bb87660e0fa0182d56a8cf6 /pycodestyle.py | |
parent | c3d2cbd744236c3a41d1013c9dce2712dcc4eee0 (diff) | |
download | pep8-397463014fda3cdefe8d6c9d117ae16d878dc494.tar.gz |
Keep compability with stdlib tokenize.py changes
https://github.com/python/cpython/commit/c4ef4896eac86a6759901c8546e26de4695a1389
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
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-x | pycodestyle.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/pycodestyle.py b/pycodestyle.py index 0d725d2..fbc3dca 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -258,10 +258,10 @@ def trailing_blank_lines(physical_line, lines, line_number, total_lines): """ if line_number == total_lines: stripped_last_line = physical_line.rstrip() - if not stripped_last_line: + if physical_line and not stripped_last_line: return 0, "W391 blank line at end of file" if stripped_last_line == physical_line: - return len(physical_line), "W292 no newline at end of file" + return len(lines[-1]), "W292 no newline at end of file" @register_check |