Permalink
Browse files

Honor # noqa for errors E711 and E712; issue #180

  • Loading branch information...
1 parent 4bc254e commit 15392bdaa73fbf9881a3f0eadd3eef5b9db1adfb @florentx florentx committed Mar 21, 2013
Showing with 33 additions and 11 deletions.
  1. +6 −0 CHANGES.txt
  2. +12 −11 pep8.py
  3. +15 −0 testsuite/noqa.py
View
6 CHANGES.txt
@@ -2,6 +2,12 @@ Changelog
=========
+1.x (unreleased)
+----------------
+
+* Honor ``# noqa`` for errors E711 and E712. (Issue #180)
+
+
1.4.5 (2013-03-06)
------------------
View
23 pep8.py
@@ -215,9 +215,7 @@ def maximum_line_length(physical_line, max_line_length):
"""
line = physical_line.rstrip()
length = len(line)
- if length > max_line_length:
- if noqa(line):
- return
+ if length > max_line_length and not noqa(line):
if hasattr(line, 'decode'): # Python 2
# The line could contain multi-byte characters
try:
@@ -383,7 +381,7 @@ def indentation(logical_line, previous_logical, indent_char,
yield 0, "E113 unexpected indentation"
-def continuation_line_indentation(logical_line, tokens, indent_level, verbose):
+def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
r"""
Continuation lines should align wrapped elements either vertically using
Python's implicit line joining inside parentheses, brackets and braces, or
@@ -411,7 +409,7 @@ def continuation_line_indentation(logical_line, tokens, indent_level, verbose):
"""
first_row = tokens[0][2][0]
nrows = 1 + tokens[-1][2][0] - first_row
- if nrows == 1 or noqa(tokens[0][4]):
+ if noqa or nrows == 1:
return
# indent_next tells us whether the next block is indented; assuming
@@ -565,11 +563,9 @@ def whitespace_before_parameters(logical_line, tokens):
E211: dict ['key'] = list[index]
E211: dict['key'] = list [index]
"""
- prev_type = tokens[0][0]
- prev_text = tokens[0][1]
- prev_end = tokens[0][3]
+ prev_type, prev_text, __, prev_end, __ = tokens[0]
for index in range(1, len(tokens)):
- token_type, text, start, end, line = tokens[index]
+ token_type, text, start, end, __ = tokens[index]
if (token_type == tokenize.OP and
text in '([' and
start != prev_end and
@@ -894,7 +890,7 @@ def explicit_line_join(logical_line, tokens):
parens -= 1
-def comparison_to_singleton(logical_line):
+def comparison_to_singleton(logical_line, noqa):
"""
Comparisons to singletons like None should always be done
with "is" or "is not", never the equality operators.
@@ -908,7 +904,7 @@ def comparison_to_singleton(logical_line):
set to some other value. The other value might have a type (such as a
container) that could be false in a boolean context!
"""
- match = COMPARE_SINGLETON_REGEX.search(logical_line)
+ match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line)
if match:
same = (match.group(1) == '==')
singleton = match.group(2)
@@ -1262,10 +1258,14 @@ def build_tokens_line(self):
"""
self.mapping = []
logical = []
+ comments = []
length = 0
previous = None
for token in self.tokens:
token_type, text = token[0:2]
+ if token_type == tokenize.COMMENT:
+ comments.append(text)
+ continue
if token_type in SKIP_TOKENS:
continue
if token_type == tokenize.STRING:
@@ -1288,6 +1288,7 @@ def build_tokens_line(self):
length += len(text)
previous = token
self.logical_line = ''.join(logical)
+ self.noqa = comments and noqa(''.join(comments))
# With Python 2, if the line ends with '\r\r\n' the assertion fails
# assert self.logical_line.strip() == self.logical_line
View
15 testsuite/noqa.py
@@ -0,0 +1,15 @@
+#: Okay
+# silence E501
+url = 'https://api.github.com/repos/sigmavirus24/Todo.txt-python/branches/master?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&?client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # noqa
@sigmavirus24
sigmavirus24 Jul 4, 2013

I'm suddenly intrigued as to how you decided on using this URL for your test.

@florentx
florentx Jul 4, 2013

mmm, it's probably coming from #27 (comment)

@sigmavirus24
sigmavirus24 Jul 4, 2013

Ah. I totally forgot about having commented with that url.

+
+# silence E128
+from functools import (partial, reduce, wraps, # noqa
+ cmp_to_key)
+
+from functools import (partial, reduce, wraps,
+ cmp_to_key) # noqa
+
+a = 1
+if a == None: # noqa
+ pass
+#:

0 comments on commit 15392bd

Please sign in to comment.