fix: properly handle backslash before multi-line string (#1828) · nedbat/coveragepy@9aaa404 (original) (raw)

Original file line number Diff line number Diff line change
@@ -57,7 +57,15 @@ def _phys_tokens(toks: TokenInfos) -> TokenInfos:
57 57 if last_ttext.endswith("\\"):
58 58 inject_backslash = False
59 59 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] == "\\":
61 69 # It's a multi-line string and the first line ends with
62 70 # a backslash, so we don't need to inject another.
63 71 inject_backslash = False