Skip to content

Commit 530fae3

Browse files
committed
Fix negative offset with E303 before a multi-line docstring; issue #269
1 parent 20d939b commit 530fae3

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

CHANGES.txt

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

44

5+
1.x (unreleased)
6+
----------------
7+
8+
* Fix negative offset with E303 before a multi-line docstring.
9+
(Issue #269)
10+
11+
512
1.5.3 (2014-04-04)
613
------------------
714

pep8.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
'**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
8989
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='])
9090
WHITESPACE = frozenset(' \t')
91-
SKIP_TOKENS = frozenset([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE,
91+
SKIP_TOKENS = frozenset([tokenize.NL, tokenize.NEWLINE,
9292
tokenize.INDENT, tokenize.DEDENT])
9393
BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines']
9494

@@ -1306,11 +1306,13 @@ def build_tokens_line(self):
13061306
previous = None
13071307
for token in self.tokens:
13081308
(token_type, text) = token[0:2]
1309+
if token_type in SKIP_TOKENS:
1310+
continue
1311+
if not mapping:
1312+
mapping.append((0, token[2]))
13091313
if token_type == tokenize.COMMENT:
13101314
comments.append(text)
13111315
continue
1312-
if token_type in SKIP_TOKENS:
1313-
continue
13141316
if token_type == tokenize.STRING:
13151317
text = mute_string(text)
13161318
if previous:
@@ -1327,18 +1329,18 @@ def build_tokens_line(self):
13271329
logical.append(fill)
13281330
length += len(fill)
13291331
length += len(text)
1330-
mapping.append((length, token))
1332+
mapping.append((length, token[3]))
13311333
logical.append(text)
13321334
previous = token
13331335
self.logical_line = ''.join(logical)
13341336
self.noqa = comments and noqa(''.join(comments))
1335-
return mapping or [(len(self.tokens[0][1]), self.tokens[0])]
1337+
return mapping
13361338

13371339
def check_logical(self):
13381340
"""Build a line from tokens and run all logical checks on it."""
13391341
self.report.increment_logical_line()
13401342
mapping = self.build_tokens_line()
1341-
(start_row, start_col) = mapping[0][1][2]
1343+
(start_row, start_col) = mapping[0][1]
13421344
start_line = self.lines[start_row - 1]
13431345
self.indent_level = expand_indent(start_line[:start_col])
13441346
if self.blank_before < self.blank_lines:
@@ -1350,10 +1352,10 @@ def check_logical(self):
13501352
print(' ' + name)
13511353
for offset, text in self.run_check(check, argument_names) or ():
13521354
if not isinstance(offset, tuple):
1353-
for token_offset, token in mapping:
1355+
for token_offset, pos in mapping:
13541356
if offset <= token_offset:
13551357
break
1356-
offset = (token[3][0], token[3][1] + offset - token_offset)
1358+
offset = (pos[0], pos[1] + offset - token_offset)
13571359
self.report_error(offset[0], offset[1], text, check)
13581360
if self.logical_line:
13591361
self.previous_indent_level = self.indent_level

testsuite/E30.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,12 @@ def a():
7979

8080
def function():
8181
pass
82+
#: E303:5:1
83+
#!python
84+
85+
86+
87+
"""This class docstring comes on line 5.
88+
It gives error E303: too many blank lines (3)
89+
"""
8290
#:

0 commit comments

Comments
 (0)