Skip to content

Commit

Permalink
Do not truncate whitespace for multi-line string (microsoft#23977)
Browse files Browse the repository at this point in the history
Resolves: microsoft#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.
  • Loading branch information
anthonykim1 committed Sep 13, 2024
1 parent 71794f5 commit 9e44466
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions python_files/normalizeSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def _get_statements(selection):
This will remove empty newlines around and within the selection, dedent it,
and split it using the result of `ast.parse()`.
"""
if '"""' in selection or "'''" in selection:
yield selection
return

# Remove blank lines within the selection to prevent the REPL from thinking the block is finished.
lines = (line for line in split_lines(selection) if line.strip() != "")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
def add(x, y):
"""Adds x to y"""
"""
Adds x
to
y
"""
# Some comment
return x + y

v = add(1, 7)
print(v)

10 changes: 8 additions & 2 deletions src/test/python_files/terminalExec/sample2_raw.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
def add(x, y):
"""Adds x to y"""
"""
Adds x
to
y
"""
# Some comment

return x + y

v = add(1, 7)
Expand Down

0 comments on commit 9e44466

Please sign in to comment.