diff options
author | Michael Hudson-Doyle <michael.hudson@canonical.com> | 2018-09-25 14:37:08 +1200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-10-01 07:31:52 +0200 |
commit | 2698cbe56b44df7974de1c3374db8700296c6fad (patch) | |
tree | 08a452d15e23132aa5c69bc19ba767561400083e | |
parent | 9ba4196c5e1083c4d058ca01c77bc0679605a1a7 (diff) | |
download | pylint-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.txt | 2 | ||||
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | pylint/checkers/format.py | 5 |
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 @@ -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 |