summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-04-14 16:58:05 +0200
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-04-14 16:58:05 +0200
commitc06b6e725221ab927bb1ebdd908c5f53649acdcb (patch)
tree06ba8fbf0b3b3b3eed1e32a8110cfc77d6a276ac
parent77bd8aef4ed98bb9f24bd9f6b02d60e1c8d0fcf3 (diff)
downloadpep8-c06b6e725221ab927bb1ebdd908c5f53649acdcb.tar.gz
Merge checker W292 with checker W391 for better performance
-rwxr-xr-xpep8.py22
-rw-r--r--testsuite/test_api.py2
2 files changed, 11 insertions, 13 deletions
diff --git a/pep8.py b/pep8.py
index 31325ec..8a3c542 100755
--- a/pep8.py
+++ b/pep8.py
@@ -171,23 +171,20 @@ def trailing_whitespace(physical_line):
return 0, "W293 blank line contains whitespace"
-def trailing_blank_lines(physical_line, lines, line_number):
+def trailing_blank_lines(physical_line, lines, line_number, total_lines):
r"""Trailing blank lines are superfluous.
Okay: spam(1)
W391: spam(1)\n
- """
- if not physical_line.rstrip() and line_number == len(lines):
- return 0, "W391 blank line at end of file"
-
-
-def missing_newline(physical_line):
- r"""The last line should have a newline.
- Reports warning W292.
+ However the last line should end with a new line (warning W292).
"""
- if physical_line.rstrip() == physical_line:
- return len(physical_line), "W292 no newline at end of file"
+ if line_number == total_lines:
+ stripped_last_line = physical_line.rstrip()
+ if not stripped_last_line:
+ return 0, "W391 blank line at end of file"
+ if stripped_last_line == physical_line:
+ return len(physical_line), "W292 no newline at end of file"
def maximum_line_length(physical_line, max_line_length, multiline):
@@ -1265,7 +1262,7 @@ class Checker(object):
def readline(self):
"""Get the next line from the input buffer."""
- if self.line_number >= len(self.lines):
+ if self.line_number >= self.total_lines:
return ''
line = self.lines[self.line_number]
self.line_number += 1
@@ -1408,6 +1405,7 @@ class Checker(object):
def check_all(self, expected=None, line_offset=0):
"""Run all checks on the input file."""
self.report.init_file(self.filename, self.lines, expected, line_offset)
+ self.total_lines = len(self.lines)
if self._ast_checks:
self.check_ast()
self.line_number = 0
diff --git a/testsuite/test_api.py b/testsuite/test_api.py
index 7a4097a..fba27c7 100644
--- a/testsuite/test_api.py
+++ b/testsuite/test_api.py
@@ -246,7 +246,7 @@ class APITestCase(unittest.TestCase):
pep8style = pep8.StyleGuide(paths=[E11])
# Default lists of checkers
- self.assertTrue(len(pep8style.options.physical_checks) > 5)
+ self.assertTrue(len(pep8style.options.physical_checks) > 4)
self.assertTrue(len(pep8style.options.logical_checks) > 10)
self.assertEqual(len(pep8style.options.ast_checks), 0)