Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmartSend removes empty lines with triple-quoted strings #23743

Open
cbrnr opened this issue Jul 4, 2024 · 8 comments · Fixed by #23977
Open

SmartSend removes empty lines with triple-quoted strings #23743

cbrnr opened this issue Jul 4, 2024 · 8 comments · Fixed by #23977
Assignees
Labels
area-repl info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@cbrnr
Copy link

cbrnr commented Jul 4, 2024

Type: Bug

Behaviour

SmartSend on a triple-quoted string containing empty lines (i.e. two or more subsequent \n) removes empty lines on execution.

Steps to reproduce:

  1. Hit Shift-Enter on the following string:
"""Hello

World




How are you?"""

The result is:

'Hello\nWorld\nHow are you?'

The expected result is:

'Hello\n\nWorld\n\n\n\n\nHow are you?'

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

2024-07-04 08:42:46.921 [info] Telemetry level is off
2024-07-04 08:42:46.921 [info] Experiments are disabled, only manually opted experiments are active.
2024-07-04 08:42:46.921 [info] Python interpreter path: ~/.pyenv/versions/3.12.4/envs/temp/bin/python
2024-07-04 08:42:47.743 [info] Starting Pylance language server.
2024-07-04 08:42:49.160 [info] > ~/.pyenv/versions/3.12.4/envs/temp/bin/python ~/.vscode/extensions/ms-python.python-2024.9.2024062703-darwin-arm64/python_files/normalizeSelection.py
2024-07-04 08:42:49.307 [info] Send text to terminal: /Users/clemens/.pyenv/versions/3.12.4/envs/temp/bin/python
2024-07-04 08:47:40.793 [info] > ~/.pyenv/versions/3.12.4/envs/temp/bin/python ~/.vscode/extensions/ms-python.python-2024.9.2024062703-darwin-arm64/python_files/normalizeSelection.py
2024-07-04 08:47:40.827 [info] Send text to terminal: """Hello
World
How are you?"""

Extension version: 2024.9.2024062703
VS Code version: Code 1.91.0 (ea1445cc7016315d0f5728f8e8b12a45dc0a7286, 2024-07-01T18:53:23.353Z)
OS version: Darwin arm64 23.5.0
Modes:

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jul 4, 2024
@anthonykim1
Copy link

@cbrnr Hello! Thank you for filing the issue. I believe this is expected behavior as we "normalize" white spaces to send to terminal and REPL. I think you should be able to repro this even when you turn off smart send, if I recall correctly.

@anthonykim1 anthonykim1 added area-repl and removed triage-needed Needs assignment to the proper sub-team labels Jul 15, 2024
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 15, 2024
@cbrnr
Copy link
Author

cbrnr commented Jul 16, 2024

Yes, I can reproduce the behavior also when SmartSend is off. However, I do not think that this is expected behavior. Executing a command should not modify ("normalize") the contents of a string, which is what is happening here. So to me, this is clearly a bug.

@hoechenberger
Copy link

I would tend to agree with @cbrnr here: if I send something to the REPL, it should not get modified. If I intended to print this string, suddenly some intentionally empty lines would be gone -- surely this cannot be right!

@anthonykim1
Copy link

Thank you all for your feedback. Let me bring this up the team.

@anthonykim1
Copy link

Good news folks. Managed to get this in August plan, so I will be investigating how to best handle this normalization of command when we send it to either terminal REPL or native REPL!

@hoechenberger
Copy link

Amazing, thanks @anthonykim1!

@anthonykim1
Copy link

anthonykim1 commented Aug 20, 2024

Hi folks! Just merged in the PR for this, that being said it should be available starting tomorrow's(August 21st) pre-release of the Python extension. Give this a try via running shift+enter on your multi line string or even an assignment to the multi-line string. Thank you all :)

@anthonykim1 anthonykim1 added the verification-needed Verification of issue is requested label Aug 26, 2024
@anthonykim1
Copy link

Verification steps:

  1. Install latest pre-release version of Python extension
  2. Open a Python file or create one with multi line string such as
"""
hello there



"""
  1. Press shift+enter and watch that new line character inside the multi-line string are NOT truncated and therefore respected.

@Yoyokrazy Yoyokrazy added the verified Verification succeeded label Aug 28, 2024
@anthonykim1 anthonykim1 reopened this Sep 11, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 11, 2024
anthonykim1 added a commit that referenced this issue Sep 11, 2024
Reverts #23977

Have to revert #23977
with issue: #23743 due
to #24069

Will revisit why #23743
is breaking if contained inside other top level (in ast term) code
block, and look into how to support
#23743 without
breaking.
anthonykim1 added a commit to anthonykim1/vscode-python that referenced this issue Sep 11, 2024
…24096)

Reverts microsoft#23977

Have to revert microsoft#23977
with issue: microsoft#23743 due
to microsoft#24069

Will revisit why microsoft#23743
is breaking if contained inside other top level (in ast term) code
block, and look into how to support
microsoft#23743 without
breaking.
anthonykim1 added a commit to anthonykim1/vscode-python that referenced this issue Sep 12, 2024
…24096)

Reverts microsoft#23977

Have to revert microsoft#23977
with issue: microsoft#23743 due
to microsoft#24069

Will revisit why microsoft#23743
is breaking if contained inside other top level (in ast term) code
block, and look into how to support
microsoft#23743 without
breaking.
anthonykim1 added a commit that referenced this issue Sep 12, 2024
…24099)

Reverts #23977

Have to revert #23977
with issue: #23743 due
to #24069

Will revisit why #23743
is breaking if contained inside other top level (in ast term) code
block, and look into how to support
#23743 without
breaking.
anthonykim1 added a commit to anthonykim1/vscode-python that referenced this issue Sep 13, 2024
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.
anthonykim1 added a commit to anthonykim1/vscode-python that referenced this issue Sep 13, 2024
…24096)

Reverts microsoft#23977

Have to revert microsoft#23977
with issue: microsoft#23743 due
to microsoft#24069

Will revisit why microsoft#23743
is breaking if contained inside other top level (in ast term) code
block, and look into how to support
microsoft#23743 without
breaking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-repl info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants