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

[BUG] (Shift + Enter) breaks when encountering triple quotes (Python REPL) #24090

Closed
epistoteles opened this issue Sep 11, 2024 · 3 comments
Closed
Assignees
Labels
triage-needed Needs assignment to the proper sub-team verified Verification succeeded

Comments

@epistoteles
Copy link

epistoteles commented Sep 11, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version:
    Version: 1.92.2 (system setup)
    Commit: fee1edb8d6d72a0ddff41e5f71a671c23ed924b9
    Date: 2024-08-14T17:29:30.058Z
    Electron: 30.1.2
    ElectronBuildId: 9870757
    Chromium: 124.0.6367.243
    Node.js: 20.14.0
    V8: 12.4.254.20-electron.0
  • OS Version:
    Windows_NT x64 10.0.22621

Description

The Shift + Enter shortcut ("Send Selection To Interactive Window") allows you to send small executable blocks of code to your terminal. This is helpful when you want to execute just one line or function and not your entire file.

For example, if you have a function

def foo():
    print("A")

    print("B")

and just put your cursor on the def foo(): line (or select the entire function code), the function defenition of foo() will be sent to your terminal and executed. VSCode does this in a smart way which ensures that you do not get an IndentationError: unexpected indent like you would get if you just copy-pasted the function definition in the terminal.

This breaks if you include triple quotes (""") or (''') anywhere in your function. VSCode still recognizes the entire function as the entity it wants to execute, and tries to send it to the terminal, but now fails to handle empty lines smartly and raises an IndentationError: unexpected indent.

It does not matter whether the pythonREPLSmartSend setting is enabled or not.

Steps to Reproduce:

  1. Create a new python file
  2. Define a function in which a new line occurs, e.g.
def this_works():
    print("A")

    print("B")
  1. Put your cursor on the function definition or select the function and press Shift + Enter
  2. This handles the empty line well and defines the function in your terminal
  3. Define a function in which a triple quote occurs, e.g.
def this_breaks_a():
    """This function breaks"""
    print("A")

    print("B")

or even

def this_breaks_b():
    print("A ''' B")

    print("B")
  1. Put your cursor on the function definition or select the function and press Shift + Enter
  2. VSCode sends the code to your Terminal, but raises an IndentationError: unexpected indent
@amunger
Copy link

amunger commented Sep 11, 2024

From what I can tell, this works in the interactive window but breaks in the terminal.
I assume because the terminal is getting the lines one at a time, and the blank line makes it think the code is finished and should be run (because of the new >>> on the errored line).
image

@amunger amunger changed the title [BUG] "Send Selection To Interactive Window" (Shift + Enter) breaks when encountering triple quotes (Python REPL) [BUG] (Shift + Enter) breaks when encountering triple quotes (Python REPL) Sep 11, 2024
@amunger amunger transferred this issue from microsoft/vscode Sep 11, 2024
@amunger amunger assigned anthonykim1 and unassigned amunger Sep 11, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 11, 2024
@anthonykim1
Copy link

@epistoteles Thanks for filing this issue: looks like dup of #24069
Lets track it in #24069

@anthonykim1 anthonykim1 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2024
@anthonykim1
Copy link

Can folks please try the latest pre-release version of the Python extension and let me know if the problem is resolved?
Want to make sure before deploying reverted changes to stable. - Thanks

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Sep 12, 2024
@anthonykim1 anthonykim1 added verified Verification succeeded and removed info-needed Issue requires more information from poster labels Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants