summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rwxr-xr-xpep8.py16
-rw-r--r--testsuite/E12.py6
3 files changed, 19 insertions, 7 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index d81a64d..7f75e4b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,6 +5,10 @@ Changelog
1.5.x (unreleased)
------------------
+Bug fixes:
+
+* Fix wrong offset computation when error is on the last char
+ of a physical line. (Issue #268)
1.5.2 (2014-04-04)
diff --git a/pep8.py b/pep8.py
index 43ff43a..a47c22c 100755
--- a/pep8.py
+++ b/pep8.py
@@ -1326,13 +1326,13 @@ class Checker(object):
fill = self.lines[end_row - 1][end:start]
logical.append(fill)
length += len(fill)
+ length += len(text)
mapping.append((length, token))
logical.append(text)
- length += len(text)
previous = token
self.logical_line = ''.join(logical)
self.noqa = comments and noqa(''.join(comments))
- return mapping or [(0, self.tokens[0])]
+ return mapping or [(len(self.tokens[0][1]), self.tokens[0])]
def check_logical(self):
"""Build a line from tokens and run all logical checks on it."""
@@ -1354,10 +1354,10 @@ class Checker(object):
(li_number, li_offset) = offset
else:
for (token_offset, token) in mapping:
- if offset < token_offset:
+ if offset <= token_offset:
break
- li_number = token[2][0]
- li_offset = (token[2][1] + offset - token_offset)
+ li_number = token[3][0]
+ li_offset = (token[3][1] + offset - token_offset)
self.report_error(li_number, li_offset, text, check)
if self.logical_line:
self.previous_indent_level = self.indent_level
@@ -1460,8 +1460,10 @@ class Checker(object):
elif COMMENT_WITH_NL and token_type == tokenize.COMMENT:
if len(self.tokens) == 1:
# The comment also ends a physical line
- text = text.rstrip('\r\n')
- self.tokens = [(token_type, text) + token[2:]]
+ token = list(token)
+ token[1] = text.rstrip('\r\n')
+ token[3] = (token[2][0], token[2][1] + len(token[1]))
+ self.tokens = [tuple(token)]
self.check_logical()
return self.report.get_file_results()
diff --git a/testsuite/E12.py b/testsuite/E12.py
index 84650f1..6ebd44e 100644
--- a/testsuite/E12.py
+++ b/testsuite/E12.py
@@ -367,4 +367,10 @@ print dedent(
# more stuff
)
)
+#: E701:1:8 E122:2:1 E203:4:8 E128:5:1
+if True:\
+print(True)
+
+print(a
+, end=' ')
#: