summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hudson-Doyle <michael.hudson@canonical.com>2018-09-25 14:37:08 +1200
committerClaudiu Popa <pcmanticore@gmail.com>2018-10-01 07:31:52 +0200
commit2698cbe56b44df7974de1c3374db8700296c6fad (patch)
tree08a452d15e23132aa5c69bc19ba767561400083e
parent9ba4196c5e1083c4d058ca01c77bc0679605a1a7 (diff)
downloadpylint-git-2698cbe56b44df7974de1c3374db8700296c6fad.tar.gz
fix compatibility with unreleased changes to stdlib tokenizer
https://github.com/python/cpython/commit/c4ef4896eac86a6759901c8546e26de4695a1389 (not yet in any released version, but it's been backported to all versions of Python in git, even 2.7!) changed the behaviour in the stdlib's tokenize module to emit a synthetic NEWLINE token even if the file does not end with a newline. This was causing a spurious "mixed-line-endings" warning to be emitted, but luckily the synthetic token is easy to test for (the token text is "").
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--ChangeLog2
-rw-r--r--pylint/checkers/format.py5
3 files changed, 8 insertions, 1 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 729d92144..1d74db964 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -239,3 +239,5 @@ contributors:
* Benjamin Drung: contributing Debian Developer
* Scott Worley: contributor
+
+* Michael Hudson-Doyle
diff --git a/ChangeLog b/ChangeLog
index f82efb5f8..6e06ec4d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@ What's New in Pylint 2.2?
Release date: TBA
+ * Fix compatibility with changes to stdlib tokenizer.
+
* ``pylint`` is less eager to consume the whole line for pragmas
Close #2485
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py
index 4ed779054..9e353e6d5 100644
--- a/pylint/checkers/format.py
+++ b/pylint/checkers/format.py
@@ -1074,7 +1074,10 @@ class FormatChecker(BaseTokenChecker):
def _check_line_ending(self, line_ending, line_num):
# check if line endings are mixed
if self._last_line_ending is not None:
- if line_ending != self._last_line_ending:
+ # line_ending == "" indicates a synthetic newline added at
+ # the end of a file that does not, in fact, end with a
+ # newline.
+ if line_ending and line_ending != self._last_line_ending:
self.add_message("mixed-line-endings", line=line_num)
self._last_line_ending = line_ending