From 9aaa404e9606e9f9784eac1400d3b2ce9ef2902d Mon Sep 17 00:00:00 2001 From: Kenshin <1427518212@qq.com> Date: Sat, 3 Aug 2024 23:14:36 +0800 Subject: [PATCH] fix: properly handle backslash before multi-line string (#1828) Co-authored-by: LiuYinCarl --- coverage/phystokens.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/coverage/phystokens.py b/coverage/phystokens.py index ec8959fb6..37aeee81f 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -57,7 +57,15 @@ def _phys_tokens(toks: TokenInfos) -> TokenInfos: if last_ttext.endswith("\\"): inject_backslash = False elif ttype == token.STRING: - if "\n" in ttext and ttext.split("\n", 1)[0][-1] == "\\": + if last_line.endswith(last_ttext+"\\\n"): + # Deal with special cases like such code:: + # + # a = ["aaa",\ + # "bbb \ + # ccc"] + # + pass + elif "\n" in ttext and ttext.split("\n", 1)[0][-1] == "\\": # It's a multi-line string and the first line ends with # a backslash, so we don't need to inject another. inject_backslash = False