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>2019-07-16 11:08:34 +0200
commit216bf7c6a07d467e672d54a632b040183449f3d8 (patch)
tree9fb87da743a6f72c1390d86876fce5152e1c598c
parent2a445e335a1530e4b0c6aa6f1e0b80f3434a5c65 (diff)
downloadpylint-git-216bf7c6a07d467e672d54a632b040183449f3d8.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.py7
3 files changed, 9 insertions, 2 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index d714c90be..856f112a4 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -164,3 +164,5 @@ Order doesn't matter (not that much, at least ;)
* Jason Owen: contributor
* Mitchell Young: minor adjustment to docparams
+
+* Michael Hudson-Doyle \ No newline at end of file
diff --git a/ChangeLog b/ChangeLog
index 64f0ec1e7..9a9d17a0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,8 @@ Release date: |TBA|
Close #2047
+ * Fix compatibility with changes to stdlib tokenizer.
+
What's New in Pylint 1.9.4?
===========================
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py
index b16a91a8a..f144e1380 100644
--- a/pylint/checkers/format.py
+++ b/pylint/checkers/format.py
@@ -871,8 +871,11 @@ 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:
- self.add_message('mixed-line-endings', line=line_num)
+ # 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