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

Indentation Errors in VS Code When Running Old Python Functions with Docstrings/Comments Using Shift + Enter #24069

Closed
kitman1250 opened this issue Sep 6, 2024 · 11 comments
Assignees
Labels
area-repl bug Issue identified by VS Code Team member as probable bug

Comments

@kitman1250
Copy link

Summary
When running my "old" Python functions in VS Code using Shift + Enter (Python Interactive Window), I encounter indentation errors on lines that contain single (') or double (") quotes at the beginning, particularly with comments or docstrings. However, if I write brand new functions with similar comments or docstrings, they run without any issues. By "old" functions, I just mean anything that is saved in a file, not written brand new. Reinstalling Python did not resolve the problem, and the issue persists even though the code is properly formatted with consistent indentation. I've been running code this way all year without issue, but this week I've started having issues.

GIF reproducing error is below

Steps to Reproduce:

  1. Find a Python function containing single-line comments or multi-line docstrings (''' or """).
  2. Highlight that function and run it using Shift + Enter.
  3. Observe the indentation errors, particularly on lines with comments or docstrings starting with ' or ".
  4. Running the full script (not in parts) works without errors.
  5. Weirdly, new functions with similar comments or docstrings run without errors when executed in the same way.

Expected Behavior:
The code should execute without indentation errors when running individual functions or code blocks, as it does when the entire script is run.

Actual Behavior:
Indentation errors occur when running individual functions with Shift + Enter, specifically related to lines with comments or docstrings.

System Information:
Operating System: Windows
OS Version: 10.0.22631
OS Release: 11
VS Code Version: 1.93
Python Version: 3.12.5
Pylance: v2024.8.2

GIF Example:
GIF: https://imgur.com/ueBj9xM

@debonte debonte removed their assignment Sep 6, 2024
@debonte debonte transferred this issue from microsoft/pylance-release Sep 6, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 6, 2024
@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Sep 9, 2024
@kitman1250
Copy link
Author

Looks like someone else is experiencing the same issue: #24083

@thunfischtoast
Copy link

Interesting. I could replicate it in a freshly created file though. I also tried setting up a new venv.
Can you tell a difference to files where the problem does not happen?

@kitman1250
Copy link
Author

@thunfischtoast Yea I can get the bug to go away with fresh functions. If I "edit" old functions to make them "new" then the issue persists.

@thunfischtoast
Copy link

thunfischtoast commented Sep 10, 2024

@thunfischtoast Yea I can get the bug to go away with fresh functions. If I "edit" old functions to make them "new" then the issue persists.

Do the "old" functions maybe have indentations in the blank lines?

E.g. this fails:

def some_function():
    """Test"""

    print("Hello World")

but this works:

def some_function():
    """Test"""
    
    print("Hello World")

@anthonykim1 anthonykim1 added area-repl and removed triage-needed Needs assignment to the proper sub-team labels Sep 11, 2024
@anthonykim1
Copy link

Thanks everyone for staying on top of this. @kitman1250 Are you on https://github.com/microsoft/vscode-python/releases/tag/v2024.14.0 2024.14.0? If so, can you downgrade to 2024.12.0 and see if you observe the same problem - thanks

@kitman1250
Copy link
Author

kitman1250 commented Sep 11, 2024

@anthonykim1 Yes that fixed it! v2024.12.0. I had reverted a few extensions to older versions before without it fixing the issue, so I must have either used the reverted the wrong ones before (maybe Pylance?) or I didn't go back far enough to v2024.12.0.

I toggled it back and forth a few times between the newest version and this version, and this definitely fixes the issue.

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
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

@PhilippLoesche
Copy link

I encountered the same issue and had to revert to an earlier version. The pre-release update resolved the problem.

@thunfischtoast
Copy link

Same here, the problem does not occur on v2024.15.2024091202 anymore. Thanks @anthonykim1 !

@kitman1250
Copy link
Author

Same, no issue on v2024.15.2024091202. Thank you @anthonykim1!

@anthonykim1
Copy link

Great, thank you everyone. Python extension 2024.14.1 is now released and it should have all the fixes for this! Let me know if anyone suffer from this problem again.

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 bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

6 participants