From 46951457f9295ed4e0859c12d8cc233b50e9c806 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 8 Nov 2012 10:30:12 -0500 Subject: [PATCH 1/4] Allow users to skip a line. This will disable pep8 for that line. It's simplistic but it works and it is an elegant (and commonplace solution) to #27. --- pep8.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pep8.py b/pep8.py index d57cdf39..86096c77 100755 --- a/pep8.py +++ b/pep8.py @@ -1197,7 +1197,10 @@ def readline(self): self.line_number += 1 if self.line_number > len(self.lines): return '' - return self.lines[self.line_number - 1] + line = self.lines[self.line_number - 1] + if line.lower().strip().endswith('# nopep8'): + return '' + return line def readline_check_physical(self): """ From 0ab87b403f405d11897a374429c2088803c85873 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 8 Nov 2012 10:44:45 -0500 Subject: [PATCH 2/4] Refactor a bit. --- pep8.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pep8.py b/pep8.py index 86096c77..d9335ecb 100755 --- a/pep8.py +++ b/pep8.py @@ -1198,9 +1198,7 @@ def readline(self): if self.line_number > len(self.lines): return '' line = self.lines[self.line_number - 1] - if line.lower().strip().endswith('# nopep8'): - return '' - return line + return '' if line.lower().strip().endswith('# nopep8') else line def readline_check_physical(self): """ From 8b2ea84300c5b99017b1cfb42553928468343f76 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 14 Nov 2012 11:56:23 -0500 Subject: [PATCH 3/4] The original modification was insufficient. You might get E90* errors since there is no line to finish the object or function/method call before the EOF. This fixes that properly. My apologies for the error. --- pep8.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pep8.py b/pep8.py index d9335ecb..b1903c89 100755 --- a/pep8.py +++ b/pep8.py @@ -477,6 +477,9 @@ def continuation_line_indentation(logical_line, tokens, indent_level, verbose): print(">>> " + tokens[0][4].rstrip()) for token_type, text, start, end, line in tokens: + if line.strip().lower().endswith('# nopep8'): + continue + newline = row < start[0] - first_row if newline: row = start[0] - first_row @@ -1197,8 +1200,7 @@ def readline(self): self.line_number += 1 if self.line_number > len(self.lines): return '' - line = self.lines[self.line_number - 1] - return '' if line.lower().strip().endswith('# nopep8') else line + return self.lines[self.line_number - 1] def readline_check_physical(self): """ From 855af3e1957c2a5a09df9de48013c96cdba10088 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sat, 1 Dec 2012 10:04:11 -0500 Subject: [PATCH 4/4] Some people reported E501 continued to appear Even though I couldn't reproduce it in a clean virtualenv, I have added this to be entirely certain that their issues do not persist. --- pep8.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pep8.py b/pep8.py index b1903c89..00b51bd0 100755 --- a/pep8.py +++ b/pep8.py @@ -264,6 +264,8 @@ def maximum_line_length(physical_line, max_line_length): line = physical_line.rstrip() length = len(line) if length > max_line_length: + if line.strip().lower().endswith('# nopep8'): + return if hasattr(line, 'decode'): # Python 2 # The line could contain multi-byte characters try: