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

pythonREPLSmartSend does not fully close a code block with a dict or set at the end #22469

Closed
GriceTurrble opened this issue Nov 2, 2023 · 8 comments
Assignees
Labels
area-repl bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@GriceTurrble
Copy link

Type: Bug

  1. Opt into the Python experiment pythonREPLSmartSend.

  2. Define a small class with one method that returns a dict:

    class Something:
        def method():
            return {"something": "abc"}
  3. Place the cursor at the end of the first line, class Something:

  4. Press Shift-Enter

The result sent to the REPL is the full definition, but it is missing the last trailing newline:

>>> class Something:
...     def method():
...         return {"something": "abc"}
... # cursor is here!

This means chaining the next line of code can result in an indentation error, because the REPL has not fully closed this multiline entry:

>>> class Something:
...     def method():
...         return {"something": "abc"}
... a = {"something_else": "abc"}
  File "<stdin>", line 4
    a = {"something_else": "abc"}
    ^
SyntaxError: invalid syntax
>>> 

Notably, I've reproduced this when the return statement returns a dict. The issue is not reproduced in the case of return "abc" or return 123.

Multiline dicts also cause the issue:

>>> class Something:
...     def method():
...         return {
...             "abc": "def",
...             "cdf": "what",
...         }
... # cursor is here

Parentheses used for multiine strings do not:

>>> class Something:
...     def method():
...         return (
...             "abc"
...             "cdf"
...         )
... 
>>> # cursor is here

VS Code version: Code 1.84.0 (Universal) (d037ac076cee195194f93ce6fe2bdfe2969cc82d, 2023-11-01T11:30:19.406Z)
OS version: Darwin arm64 22.1.0
Modes:

System Info
Item Value
CPUs Apple M1 Pro (10 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 9, 8, 7
Memory (System) 16.00GB (0.12GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (53)
Extension Author (truncated) Version
vscode-sqlite ale 0.14.1
vscode-django bat 1.14.0
markdown-mermaid bie 1.20.0
markdown-preview-github-styles bie 2.0.3
prettier-toml bod 0.1.0
ruff cha 2023.44.0
npm-intellisense chr 1.4.5
csharpier-vscode csh 1.3.6
vscode-eslint dba 2.4.2
gitlens eam 14.4.1
vsc-material-theme Equ 33.10.5
vsc-material-theme-icons equ 3.1.4
prettier-vscode esb 10.1.0
vscode-reveal evi 4.3.3
codespaces Git 1.16.2
vscode-github-actions git 0.26.2
vscode-pull-request-github Git 0.76.0
cloudcode goo 2.1.1
gc-excelviewer Gra 4.2.58
terraform has 2.28.2
prettier-sql-vscode inf 1.6.0
git-graph mhu 1.30.0
vscode-docker ms- 1.27.0
csdevkit ms- 1.0.14
csharp ms- 2.9.20
dotnet-interactive-vscode ms- 1.0.4517010
vscode-dotnet-runtime ms- 2.0.0
vscode-kubernetes-tools ms- 1.3.15
black-formatter ms- 2023.4.1
isort ms- 2023.10.1
mypy-type-checker ms- 2023.4.0
python ms- 2023.20.0
vscode-pylance ms- 2023.10.50
jupyter ms- 2023.10.1003070148
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.0.17
vscode-jupyter-cell-tags ms- 0.1.8
vscode-jupyter-slideshow ms- 0.1.5
remote-containers ms- 0.321.0
remote-wsl ms- 0.81.8
powershell ms- 2023.8.0
vscode-github-issue-notebooks ms- 0.0.130
vsliveshare ms- 1.0.5892
vsliveshare-pack ms- 0.4.0
jekyll ost 0.1.1
postman-for-vscode Pos 0.13.1
vscode-commons red 0.0.6
vscode-yaml red 1.14.0
svelte-vscode sve 107.12.0
even-better-toml tam 0.19.2
tilt Tch 1.0.9
tiltfile til 0.0.3
markdown-all-in-one yzh 3.5.1

(5 theme extensions excluded)

@GriceTurrble
Copy link
Author

GriceTurrble commented Nov 2, 2023

Update, this is a little more universal to code blocks with some object ending with }:

>>> def method():
...     return {
...         "abc": "def",
...         "cdf": "what",
...     }
... # cursor
>>> if True:
...     a = {
...         "abc": "def",
...         "cdf": "what",
...     }
... # cursor
>>> if True:
...     a = {"abc": "def"}
... # cursor

Also works with a set:

>>> if True:
...     a = {"abc"}
... # cursor

@GriceTurrble GriceTurrble changed the title pythonREPLSmartSend does not fully close out a class definition in some instances pythonREPLSmartSend does not fully close a code block with a dict or set at the end Nov 2, 2023
@vscodenpa vscodenpa added the triage-needed Needs assignment to the proper sub-team label Nov 2, 2023
@roblourens roblourens assigned karrtikr and anthonykim1 and unassigned roblourens and aeschli Nov 13, 2023
@vscodenpa vscodenpa removed triage-needed Needs assignment to the proper sub-team labels Nov 13, 2023
@karrtikr karrtikr transferred this issue from microsoft/vscode Nov 13, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Nov 13, 2023
@anthonykim1 anthonykim1 self-assigned this Nov 13, 2023
@martj42
Copy link

martj42 commented Apr 12, 2024

Seems like the same thing happens when a code block ends with a ].

For example:

def cool_numbers():
    return [42, 99]

or

def cool_numbers():
    numbers = [42, 99]
    return numbers[1]

@anthonykim1
Copy link

can you try trying this again? With the latest version of Python extension

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

martj42 commented Nov 21, 2024

Seems to be working fine now.

@GriceTurrble
Copy link
Author

I am on a different machine these days, but latest version is acting a bit different even from this.

File contents:

class Something:
    def method(self):
        return {"something": "abc"}


print("hi")

I place my cursor on class Something and press Shift-Enter, and this happens:

$ .../.venv/bin/python
Python 3.13.0 (main, Oct 11 2024, 15:01:10) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
KeyboardInterrupt
>>> class Something:
...         def method(self):
...                         return {"something": "abc"}
...                         # Cursor is here

This may be due to the changes in the Python 3.13 REPL, which will automatically indent on new lines in a block. If I re-send it, there are more spaces in the indent each time it is sent.

If I exit that REPL and start Python 3.12 in the same terminal, the old result still happens:

>>> 
KeyboardInterrupt
>>> class Something:
...     def method(self):
...         return {"something": "abc"}
... # Cursor is here

Regenerating my new diagnostic data here:

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

XXX

Extension version: 2024.20.0
VS Code version: Code 1.95.3 (Universal) (f1a4fb101478ce6ec82fe9627c43efbf9e98c813, 2024-11-13T14:50:04.152Z)
OS version: Darwin arm64 24.0.0
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.13.0
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Pyenv
  • Value of the python.languageServer setting: Pylance
User Settings

Multiroot scenario, following user settings may not apply:

languageServer: "Pylance"

terminal
• activateEnvironment: false

Installed Extensions
Extension Name Extension Id Version
:emojisense: bierner.emojisense 0.10.0
Angular Language Service Angular.ng-template 19.0.2
angular2-switcher infinity1207.angular2-switcher 0.4.0
Azure Repos ms-vscode.azure-repos 0.40.0
Black Formatter ms-python.black-formatter 2024.4.0
Debugger for Java vscjava.vscode-java-debug 0.58.1
Dependi fill-labs.dependi 0.7.13
Dev Containers ms-vscode-remote.remote-containers 0.388.0
Django batisteo.vscode-django 1.15.0
Docker ms-azuretools.vscode-docker 1.29.3
Dracula Theme Official dracula-theme.theme-dracula 2.25.1
EditorConfig for VS Code EditorConfig.EditorConfig 0.16.4
ESLint dbaeumer.vscode-eslint 3.0.10
Even Better TOML tamasfe.even-better-toml 0.19.2
Excel Viewer GrapeCity.gc-excelviewer 4.2.62
Extension Pack for Java vscjava.vscode-java-pack 0.29.0
Git Graph mhutchie.git-graph 1.30.0
GitHub Actions github.vscode-github-actions 0.27.0
GitHub Codespaces GitHub.codespaces 1.17.3
GitHub Copilot GitHub.copilot 1.245.0
GitHub Copilot Chat GitHub.copilot-chat 0.22.4
GitHub Issue Notebooks ms-vscode.vscode-github-issue-notebooks 0.0.130
GitHub Pull Requests GitHub.vscode-pull-request-github 0.100.3
GitHub Repositories GitHub.remotehub 0.64.0
GitHub Sharp Theme joaomoreno.github-sharp-theme 1.10.0
GitHub Theme GitHub.github-vscode-theme 6.3.5
GitLens — Git supercharged eamodio.gitlens 16.0.4
Google Java Format for VS Code josevseb.google-java-format-for-vs-code 1.1.2
Gradle for Java vscjava.vscode-gradle 3.16.4
HashiCorp Terraform hashicorp.terraform 2.34.0
IntelliCode VisualStudioExptTeam.vscodeintellicode 1.3.2
IntelliCode API Usage Examples VisualStudioExptTeam.intellicode-api-usage-examples 0.2.9
isort ms-python.isort 2023.10.1
Java Oracle.oracle-java 23.0.0
JavaScript Debugger ms-vscode.js-debug 1.95.3
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.3
Jekyll Problem Matchers osteele.jekyll 0.1.1
Jest Runner firsttris.vscode-jest-runner 0.4.74
Jupyter ms-toolsai.jupyter 2024.10.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.21
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Kubernetes ms-kubernetes-tools.vscode-kubernetes-tools 1.3.18
Language Support for Java(TM) by Red Hat redhat.java 1.36.0
Live Server ritwickdey.LiveServer 5.7.9
Live Share ms-vsliveshare.vsliveshare 1.0.5941
Markdown All in One yzhang.markdown-all-in-one 3.6.2
Markdown Preview Github Styling bierner.markdown-preview-github-styles 2.1.0
Markdown Preview Mermaid Support bierner.markdown-mermaid 1.27.0
Material Theme — Free Equinusocio.vsc-material-theme 34.7.9
Material Theme Icons — Free equinusocio.vsc-material-theme-icons 3.8.10
Maven for Java vscjava.vscode-maven 0.44.0
Mypy Type Checker ms-python.mypy-type-checker 2024.0.0
npm Intellisense christian-kohler.npm-intellisense 1.4.5
Nx Console nrwl.angular-console 18.31.1
Postman Postman.postman-for-vscode 1.5.0
Prettier - Code formatter esbenp.prettier-vscode 11.0.0
Prettier SQL VSCode inferrinizzard.prettier-sql-vscode 1.6.0
Prettier TOML bodil.prettier-toml 0.1.0
Project Manager for Java vscjava.vscode-java-dependency 0.24.1
Protobuf support peterj.proto 0.0.4
Pylance ms-python.vscode-pylance 2024.11.3
Python ms-python.python 2024.20.0
Python Debugger ms-python.debugpy 2024.12.0
Rainglow daylerees.rainglow 1.5.2
Red Hat Commons redhat.vscode-commons 0.0.6
Remote Repositories ms-vscode.remote-repositories 0.42.0
Ruff charliermarsh.ruff 2024.56.0
rust 1YiB.rust-bundle 1.0.0
Rust Syntax dustypomerleau.rust-syntax 0.6.1
rust-analyzer rust-lang.rust-analyzer 0.3.2196
Spring Initializr Java Support vscjava.vscode-spring-initializr 0.11.2
SQLite alexcvzz.vscode-sqlite 0.14.1
Svelte for VS Code svelte.svelte-vscode 109.3.2
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.10
Tailwind CSS IntelliSense bradlc.vscode-tailwindcss 0.12.15
Test Runner for Java vscjava.vscode-java-test 0.43.0
Tiltfile tilt-dev.tiltfile 0.0.4
vscode-just nefrob.vscode-just-syntax 0.6.0
vscode-reveal evilz.vscode-reveal 4.3.3
WSL ms-vscode-remote.remote-wsl 0.88.5
XML redhat.vscode-xml 0.27.2
YAML redhat.vscode-yaml 1.15.0
System Info
Item Value
CPUs Apple M3 Pro (12 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 2, 2, 2
Memory (System) 18.00GB (0.09GB free)
Process Argv
Screen Reader no
VM 0%

@anthonykim1
Copy link

@martj42 Glad the issue is resolved!

@GriceTurrble Thats a different issue - dup of #24422
it should be resolved in vs code insiders and latest pre-release of Python extension :)

@GriceTurrble
Copy link
Author

It should be noted that the original issue here is still happening on my end, regardless of the KeyboardInterrupt exception.

@anthonykim1 anthonykim1 added the bug Issue identified by VS Code Team member as probable bug label Feb 4, 2025
@anthonykim1
Copy link

Good point @GriceTurrble
Lets combine it and track it here: #24565

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-repl bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

7 participants