Fix an incorrect "W391 blank line at EOF"
authorGreg Ward <greg@gerg.ca>
Fri, 8 Nov 2013 20:37:14 +0000 (15:37 -0500)
committerGreg Ward <greg@gerg.ca>
Fri, 8 Nov 2013 21:19:26 +0000 (16:19 -0500)
It only happens when there is a multiline string at EOF that happens
to contain a blank line. Introduced by my special treatment of
multiline strings.

pep8.py
testsuite/W39no.py [new file with mode: 0644]

diff --git a/pep8.py b/pep8.py
index e2ffbbcf9b24d2e3b36434546320bbeb804476ae..ce3feb0e08bce5a68ec7869de7c3b2f84af6015a 100755 (executable)
--- a/pep8.py
+++ b/pep8.py
@@ -1249,7 +1249,7 @@ class Checker(object):
             arguments.append(getattr(self, name))
         return check(*arguments)
 
-    def check_physical(self, line_number, line):
+    def check_physical(self, line):
         """
         Run all physical checks on a raw input line.
         """
@@ -1258,7 +1258,7 @@ class Checker(object):
             result = self.run_check(check, argument_names)
             if result is not None:
                 offset, text = result
-                self.report_error(line_number, offset, text, check)
+                self.report_error(self.line_number, offset, text, check)
 
     def build_tokens_line(self):
         """
@@ -1358,12 +1358,12 @@ class Checker(object):
             # *not* check the last line: its newline is outside of the
             # multiline string, so we consider it a regular physical line
             # (it will be checked when we see the newline token).
-            line_number = token[2][0]
+            self.line_number = token[2][0]
             for line in token[1].split('\n')[:-1]:
-                self.check_physical(line_number, line + '\n')
-                line_number += 1
+                self.check_physical(line + '\n')
+                self.line_number += 1
         elif token[0] in (tokenize.NEWLINE, tokenize.NL):
-            self.check_physical(self.line_number, token[4])
+            self.check_physical(token[4])
 
     def check_all(self, expected=None, line_offset=0):
         """
diff --git a/testsuite/W39no.py b/testsuite/W39no.py
new file mode 100644 (file)
index 0000000..2948b82
--- /dev/null
@@ -0,0 +1,6 @@
+#: Okay
+'''there is nothing wrong
+with a multiline string at EOF
+
+that happens to have a blank line in it
+'''