Skip to content

Commit 9aaa404

Browse files
LiuYinCarlLiuYinCarl
and
LiuYinCarl
authored
fix: properly handle backslash before multi-line string (#1828)
Co-authored-by: LiuYinCarl <[email protected]>
1 parent 9c50270 commit 9aaa404

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

coverage/phystokens.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ def _phys_tokens(toks: TokenInfos) -> TokenInfos:
5757
if last_ttext.endswith("\\"):
5858
inject_backslash = False
5959
elif ttype == token.STRING:
60-
if "\n" in ttext and ttext.split("\n", 1)[0][-1] == "\\":
60+
if last_line.endswith(last_ttext+"\\\n"):
61+
# Deal with special cases like such code::
62+
#
63+
# a = ["aaa",\
64+
# "bbb \
65+
# ccc"]
66+
#
67+
pass
68+
elif "\n" in ttext and ttext.split("\n", 1)[0][-1] == "\\":
6169
# It's a multi-line string and the first line ends with
6270
# a backslash, so we don't need to inject another.
6371
inject_backslash = False

0 commit comments

Comments
 (0)