summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-04-05 22:52:14 +0200
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-04-05 22:52:14 +0200
commit530fae3ed83470286a7972835d38d156d9991539 (patch)
treefadb9aa4755fab65043cc7d328a6faad1ad52794
parent20d939b22daf8819731748eb1f7149c87e320102 (diff)
downloadpep8-530fae3ed83470286a7972835d38d156d9991539.tar.gz
Fix negative offset with E303 before a multi-line docstring; issue #269
-rw-r--r--CHANGES.txt7
-rwxr-xr-xpep8.py18
-rw-r--r--testsuite/E30.py8
3 files changed, 25 insertions, 8 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 9fe2257..3baef5e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,13 @@ Changelog
=========
+1.x (unreleased)
+----------------
+
+* Fix negative offset with E303 before a multi-line docstring.
+ (Issue #269)
+
+
1.5.3 (2014-04-04)
------------------
diff --git a/pep8.py b/pep8.py
index ce80fb1..9e7bcbf 100755
--- a/pep8.py
+++ b/pep8.py
@@ -88,7 +88,7 @@ WS_NEEDED_OPERATORS = frozenset([
'**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>',
'%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '='])
WHITESPACE = frozenset(' \t')
-SKIP_TOKENS = frozenset([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE,
+SKIP_TOKENS = frozenset([tokenize.NL, tokenize.NEWLINE,
tokenize.INDENT, tokenize.DEDENT])
BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines']
@@ -1306,11 +1306,13 @@ class Checker(object):
previous = None
for token in self.tokens:
(token_type, text) = token[0:2]
+ if token_type in SKIP_TOKENS:
+ continue
+ if not mapping:
+ mapping.append((0, token[2]))
if token_type == tokenize.COMMENT:
comments.append(text)
continue
- if token_type in SKIP_TOKENS:
- continue
if token_type == tokenize.STRING:
text = mute_string(text)
if previous:
@@ -1327,18 +1329,18 @@ class Checker(object):
logical.append(fill)
length += len(fill)
length += len(text)
- mapping.append((length, token))
+ mapping.append((length, token[3]))
logical.append(text)
previous = token
self.logical_line = ''.join(logical)
self.noqa = comments and noqa(''.join(comments))
- return mapping or [(len(self.tokens[0][1]), self.tokens[0])]
+ return mapping
def check_logical(self):
"""Build a line from tokens and run all logical checks on it."""
self.report.increment_logical_line()
mapping = self.build_tokens_line()
- (start_row, start_col) = mapping[0][1][2]
+ (start_row, start_col) = mapping[0][1]
start_line = self.lines[start_row - 1]
self.indent_level = expand_indent(start_line[:start_col])
if self.blank_before < self.blank_lines:
@@ -1350,10 +1352,10 @@ class Checker(object):
print(' ' + name)
for offset, text in self.run_check(check, argument_names) or ():
if not isinstance(offset, tuple):
- for token_offset, token in mapping:
+ for token_offset, pos in mapping:
if offset <= token_offset:
break
- offset = (token[3][0], token[3][1] + offset - token_offset)
+ offset = (pos[0], pos[1] + offset - token_offset)
self.report_error(offset[0], offset[1], text, check)
if self.logical_line:
self.previous_indent_level = self.indent_level
diff --git a/testsuite/E30.py b/testsuite/E30.py
index 0208d05..d2d7bf3 100644
--- a/testsuite/E30.py
+++ b/testsuite/E30.py
@@ -79,4 +79,12 @@ def a():
def function():
pass
+#: E303:5:1
+#!python
+
+
+
+"""This class docstring comes on line 5.
+It gives error E303: too many blank lines (3)
+"""
#: