diff options
author | Marius Gedminas <marius@gedmin.as> | 2018-11-22 15:13:47 +0200 |
---|---|---|
committer | Marius Gedminas <marius@gedmin.as> | 2018-11-22 15:13:47 +0200 |
commit | cb8402add912fa162a42eef9067c446704d919d3 (patch) | |
tree | 3c3ebee97b4885bf3bc0945905b66143b411c23c /pycodestyle.py | |
parent | b49f5e75be2e942f264f75acc6a7713c593c5615 (diff) | |
download | pep8-cb8402add912fa162a42eef9067c446704d919d3.tar.gz |
Make W605 point to the invalid sequence
Instead of having W605 point to the beginning of the string literal,
make it point to the precise line and column of the invalid escape sequence.
This is more helpful when you have multiline string literals.
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-x | pycodestyle.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/pycodestyle.py b/pycodestyle.py index 8b608b0..5b66302 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1522,7 +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 + start_line, start_col = 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,8 +1535,13 @@ def python_3000_invalid_escape_sequence(logical_line, tokens): while pos >= 0: pos += 1 if string[pos] not in valid: + line = start_line + string[:pos].count('\n') + if line == start_line: + col = start_col + len(prefix) + len(quote) + pos + else: + col = pos - string.rfind('\n', 0, pos) - 1 yield ( - orig_start, + (line, col - 1), "W605 invalid escape sequence '\\%s'" % string[pos], ) |