Skip to content

Commit

Permalink
Merge pull request #808 from asottile/invalid_escape_sequence_offset
Browse files Browse the repository at this point in the history
Fix line offset for 'invalid escape sequence'
  • Loading branch information
sigmavirus24 committed Oct 25, 2018
2 parents c3d2cbd + 59f7604 commit 77ad772
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_.

Expand Down
3 changes: 2 additions & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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],
)
Expand Down
8 changes: 6 additions & 2 deletions testsuite/W60.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
x = 0
#: W604
val = `1 + 2`
#: W605
#: W605:1:9
regex = '\.png$'
#: W605
#: W605:1:9
regex = '''
\.png$
'''
#: W605:2:5
f(
'\_'
)
#: Okay
regex = r'\.png$'
regex = '\\.png$'
Expand Down

0 comments on commit 77ad772

Please sign in to comment.