Skip to content

Commit e751377

Browse files
authored
Do not truncate whitespace for multi-line string (#23977)
Resolves: #23743 It seems that when people have a multi line string such surrounded by """ quotes, the white spacing inside the quote is very much intentional, and so if we detect that they are in such code-block, we would rather not normalize/truncate the white spaces for that specific code block.
1 parent fdddaf9 commit e751377

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

python_files/normalizeSelection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def _get_statements(selection):
2626
This will remove empty newlines around and within the selection, dedent it,
2727
and split it using the result of `ast.parse()`.
2828
"""
29+
if '"""' in selection or "'''" in selection:
30+
yield selection
31+
return
32+
2933
# Remove blank lines within the selection to prevent the REPL from thinking the block is finished.
3034
lines = (line for line in split_lines(selection) if line.strip() != "")
3135

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
def add(x, y):
2-
"""Adds x to y"""
2+
"""
3+
4+
Adds x
5+
to
6+
y
7+
8+
9+
"""
310
# Some comment
411
return x + y
512

613
v = add(1, 7)
714
print(v)
15+

src/test/python_files/terminalExec/sample2_raw.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
def add(x, y):
2-
"""Adds x to y"""
2+
"""
3+
4+
Adds x
5+
to
6+
y
7+
8+
9+
"""
310
# Some comment
4-
511
return x + y
612

713
v = add(1, 7)

0 commit comments

Comments
 (0)