Skip to content

Commit 15392bd

Browse files
committed
Honor # noqa for errors E711 and E712; issue #180
1 parent 4bc254e commit 15392bd

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Changelog
22
=========
33

44

5+
1.x (unreleased)
6+
----------------
7+
8+
* Honor ``# noqa`` for errors E711 and E712. (Issue #180)
9+
10+
511
1.4.5 (2013-03-06)
612
------------------
713

pep8.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ def maximum_line_length(physical_line, max_line_length):
215215
"""
216216
line = physical_line.rstrip()
217217
length = len(line)
218-
if length > max_line_length:
219-
if noqa(line):
220-
return
218+
if length > max_line_length and not noqa(line):
221219
if hasattr(line, 'decode'): # Python 2
222220
# The line could contain multi-byte characters
223221
try:
@@ -383,7 +381,7 @@ def indentation(logical_line, previous_logical, indent_char,
383381
yield 0, "E113 unexpected indentation"
384382

385383

386-
def continuation_line_indentation(logical_line, tokens, indent_level, verbose):
384+
def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
387385
r"""
388386
Continuation lines should align wrapped elements either vertically using
389387
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):
411409
"""
412410
first_row = tokens[0][2][0]
413411
nrows = 1 + tokens[-1][2][0] - first_row
414-
if nrows == 1 or noqa(tokens[0][4]):
412+
if noqa or nrows == 1:
415413
return
416414

417415
# indent_next tells us whether the next block is indented; assuming
@@ -565,11 +563,9 @@ def whitespace_before_parameters(logical_line, tokens):
565563
E211: dict ['key'] = list[index]
566564
E211: dict['key'] = list [index]
567565
"""
568-
prev_type = tokens[0][0]
569-
prev_text = tokens[0][1]
570-
prev_end = tokens[0][3]
566+
prev_type, prev_text, __, prev_end, __ = tokens[0]
571567
for index in range(1, len(tokens)):
572-
token_type, text, start, end, line = tokens[index]
568+
token_type, text, start, end, __ = tokens[index]
573569
if (token_type == tokenize.OP and
574570
text in '([' and
575571
start != prev_end and
@@ -894,7 +890,7 @@ def explicit_line_join(logical_line, tokens):
894890
parens -= 1
895891

896892

897-
def comparison_to_singleton(logical_line):
893+
def comparison_to_singleton(logical_line, noqa):
898894
"""
899895
Comparisons to singletons like None should always be done
900896
with "is" or "is not", never the equality operators.
@@ -908,7 +904,7 @@ def comparison_to_singleton(logical_line):
908904
set to some other value. The other value might have a type (such as a
909905
container) that could be false in a boolean context!
910906
"""
911-
match = COMPARE_SINGLETON_REGEX.search(logical_line)
907+
match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line)
912908
if match:
913909
same = (match.group(1) == '==')
914910
singleton = match.group(2)
@@ -1262,10 +1258,14 @@ def build_tokens_line(self):
12621258
"""
12631259
self.mapping = []
12641260
logical = []
1261+
comments = []
12651262
length = 0
12661263
previous = None
12671264
for token in self.tokens:
12681265
token_type, text = token[0:2]
1266+
if token_type == tokenize.COMMENT:
1267+
comments.append(text)
1268+
continue
12691269
if token_type in SKIP_TOKENS:
12701270
continue
12711271
if token_type == tokenize.STRING:
@@ -1288,6 +1288,7 @@ def build_tokens_line(self):
12881288
length += len(text)
12891289
previous = token
12901290
self.logical_line = ''.join(logical)
1291+
self.noqa = comments and noqa(''.join(comments))
12911292
# With Python 2, if the line ends with '\r\r\n' the assertion fails
12921293
# assert self.logical_line.strip() == self.logical_line
12931294

testsuite/noqa.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#: Okay
2+
# silence E501
3+
url = 'https://api.github.com/repos/sigmavirus24/Todo.txt-python/branches/master?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&?client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # noqa
4+
5+
# silence E128
6+
from functools import (partial, reduce, wraps, # noqa
7+
cmp_to_key)
8+
9+
from functools import (partial, reduce, wraps,
10+
cmp_to_key) # noqa
11+
12+
a = 1
13+
if a == None: # noqa
14+
pass
15+
#:

0 commit comments

Comments
 (0)