diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2019-07-12 10:24:35 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-08-10 20:43:07 -0400 |
commit | 1a27df4c768e5a183ddd0f890d139996ffc52778 (patch) | |
tree | b2096def51238409ab6fedb6c34e9acae0a08ca2 /coverage/phystokens.py | |
parent | 6b3017454af6662dde107755f1ee92153e69a4d8 (diff) | |
download | python-coveragepy-git-1a27df4c768e5a183ddd0f890d139996ffc52778.tar.gz |
Fix unusual backslash token issue. #822
Diffstat (limited to 'coverage/phystokens.py')
-rw-r--r-- | coverage/phystokens.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/coverage/phystokens.py b/coverage/phystokens.py index ccfe63b3..b6866e7d 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -27,7 +27,7 @@ def phys_tokens(toks): """ last_line = None last_lineno = -1 - last_ttype = None + last_ttext = None for ttype, ttext, (slineno, scol), (elineno, ecol), ltext in toks: if last_lineno != elineno: if last_line and last_line.endswith("\\\n"): @@ -47,9 +47,7 @@ def phys_tokens(toks): # so we need to figure out if the backslash is already in the # string token or not. inject_backslash = True - if last_ttype == tokenize.COMMENT: - # Comments like this \ - # should never result in a new token. + if last_ttext.endswith("\\"): inject_backslash = False elif ttype == token.STRING: if "\n" in ttext and ttext.split('\n', 1)[0][-1] == '\\': @@ -66,7 +64,8 @@ def phys_tokens(toks): last_line ) last_line = ltext - last_ttype = ttype + if ttype not in (tokenize.NEWLINE, tokenize.NL): + last_ttext = ttext yield ttype, ttext, (slineno, scol), (elineno, ecol), ltext last_lineno = elineno |