summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2018-10-20 17:08:01 -0700
committerAnthony Sottile <asottile@umich.edu>2018-10-20 17:08:01 -0700
commit7004708c968440f94d9583c2a6154d8bc50844a4 (patch)
tree90cd2c506119f5f0153635018ab605d61bf82c4e
parentc3d2cbd744236c3a41d1013c9dce2712dcc4eee0 (diff)
downloadpep8-7004708c968440f94d9583c2a6154d8bc50844a4.tar.gz
Fix line offset for 'invalid escape sequence'
-rw-r--r--CONTRIBUTING.rst2
-rwxr-xr-xpycodestyle.py3
-rw-r--r--testsuite/W60.py4
3 files changed, 7 insertions, 2 deletions
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index f55c5e9..18b5a88 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -62,7 +62,7 @@ All the tests should pass for all available interpreters, with the summary of::
congratulations :)
-At this point you can create a pull request back to the official pycodestyles
+At this point you can create a pull request back to the official pycodestyle
repository for review! For more information on how to make a pull request,
GitHub has an excellent `guide`_.
diff --git a/pycodestyle.py b/pycodestyle.py
index 0d725d2..8b608b0 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -1522,6 +1522,7 @@ def python_3000_invalid_escape_sequence(logical_line, tokens):
for token_type, text, start, end, line in tokens:
if token_type == tokenize.STRING:
+ orig_start = start
quote = text[-3:] if text[-3:] in ('"""', "'''") else text[-1]
# Extract string modifiers (e.g. u or r)
quote_pos = text.index(quote)
@@ -1535,7 +1536,7 @@ def python_3000_invalid_escape_sequence(logical_line, tokens):
pos += 1
if string[pos] not in valid:
yield (
- line.lstrip().find(text),
+ orig_start,
"W605 invalid escape sequence '\\%s'" %
string[pos],
)
diff --git a/testsuite/W60.py b/testsuite/W60.py
index 030bec5..3f1b77c 100644
--- a/testsuite/W60.py
+++ b/testsuite/W60.py
@@ -19,6 +19,10 @@ regex = '\.png$'
regex = '''
\.png$
'''
+#: W605:2:5
+f(
+ '\_'
+)
#: Okay
regex = r'\.png$'
regex = '\\.png$'