Check the last line even if it does not end with a NL; issue #286
authorFlorent Xicluna <florent.xicluna@gmail.com>
Wed, 7 May 2014 20:12:42 +0000 (22:12 +0200)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Wed, 7 May 2014 20:12:42 +0000 (22:12 +0200)
CHANGES.txt
pep8.py
testsuite/W29.py

index d8571b55b8aaed8042c5541575336723f414b858..fd462b9302d7406f356d8372326ba65a6e72adcd 100644 (file)
@@ -12,6 +12,8 @@ Bug fixes:
 * Do not exit when an option in ``setup.cfg`` or ``tox.ini``
   is not recognized.
 
+* Check the last line even if it does not end with a newline. (Issue #286)
+
 
 1.5.6 (2014-04-14)
 ------------------
diff --git a/pep8.py b/pep8.py
index bc9113743f38c6b99850f81baa70ed25be2356db..0d7e294261691e5817ad7d1f2c52c9d93e9bfe16 100755 (executable)
--- a/pep8.py
+++ b/pep8.py
@@ -1367,6 +1367,8 @@ class Checker(object):
         tokengen = tokenize.generate_tokens(self.readline)
         try:
             for token in tokengen:
+                if token[2][0] > self.total_lines:
+                    return
                 self.maybe_check_physical(token)
                 yield token
         except (SyntaxError, tokenize.TokenError):
@@ -1449,10 +1451,8 @@ class Checker(object):
                         token[3] = (token[2][0], token[2][1] + len(token[1]))
                         self.tokens = [tuple(token)]
                         self.check_logical()
-        if len(self.tokens) > 1 and (token_type == tokenize.ENDMARKER and
-                                     self.tokens[-2][0] not in SKIP_TOKENS):
-            self.tokens.pop()
-            self.check_physical(self.tokens[-1][4])
+        if self.tokens:
+            self.check_physical(self.lines[-1])
             self.check_logical()
         return self.report.get_file_results()
 
index 688667f0eaa6d72b9f0d6cf32eca6ad9cf250785..4050c2ff6a3db09bdf67e4a7068dfbf72bd4adb3 100644 (file)
@@ -15,3 +15,7 @@ string with trailing whitespace'''
 1+ 1
 #: W292:1:27 E261:1:12 noeol
 import this # no line feed
+#: W292:3:22 noeol
+class Test(object):
+    def __repr__(self):
+        return 'test'