Skip to content

Commit

Permalink
fix: properly handle backslash before multi-line string (#1828)
Browse files Browse the repository at this point in the history
Co-authored-by: LiuYinCarl <[email protected]>
  • Loading branch information
LiuYinCarl and LiuYinCarl committed Aug 3, 2024
1 parent 9c50270 commit 9aaa404
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion coverage/phystokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9aaa404

Please sign in to comment.