Skip to content

Commit 12e4728

Browse files
committed
fix: coderabbitai
1 parent 117c6f0 commit 12e4728

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

src/snakemake/parser.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -133,38 +133,11 @@ def parse_fstring(self, token: tokenize.TokenInfo):
133133
Luckily, each token records the content of the line,
134134
and we can just take what we want there.
135135
"""
136-
lines_contents = dict()
137-
138-
def collect_lines(token_: tokenize.TokenInfo):
139-
# iterate over all lines that the token spans
140-
token_string = token_.line
141-
i = token_.start[0]
142-
while i <= token_.end[0]:
143-
end_of_line_index = (
144-
(token_string.index("\n") + 1)
145-
if "\n" in token_string
146-
else len(token_string)
147-
)
148-
line_content = token_string[:end_of_line_index]
149-
150-
# don't take the new line content if the one already stored is longer
151-
if i not in lines_contents or len(lines_contents[i]) < len(
152-
line_content
153-
):
154-
lines_contents[i] = line_content
155-
156-
# remainder of the line after the newline character
157-
token_string = token_string[end_of_line_index:]
158-
i += 1
159-
160-
# Collect lines for the first and subsequent tokens that are part of the f-string
161-
collect_lines(token)
162-
related_lines = token.start[0]
163136
lines = dict(split_token_lines(token))
164137
isin_fstring = 1
165138
for t1 in self.snakefile:
166-
if t1.end[0] not in lines:
167-
lines.update(split_token_lines(t1))
139+
# if t1.end[0] not in lines: for safety, check all tokens
140+
lines.update(split_token_lines(t1))
168141
if t1.type == tokenize.FSTRING_START:
169142
isin_fstring += 1
170143
elif t1.type == tokenize.FSTRING_END:

tests/test_fstring/Snakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,13 @@ part_one = "foo"
5959
an_fstring = f'{part_one}/{"bar" if True else "baz"}'
6060
another_fstring = f"{part_one.replace('foo', 'bar')}/{{escaped}}"
6161
multiple_parts_fstring = f"no_replacement_" "regular_string_" f"{'bar' if True else 'baz'}"
62+
63+
# Regression for issue #3700: preserve pure-literal middle line in multi-line f-strings
64+
assert (
65+
f"""abc
66+
def
67+
{1+1}"""
68+
== """abc
69+
def
70+
2"""
71+
)

0 commit comments

Comments
 (0)