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

IndentationError: unexpected indent when trying to "Debug cell" on indented code #1287

Closed
syagev opened this issue Nov 13, 2019 · 4 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug interactive-window-debugging

Comments

@syagev
Copy link

syagev commented Nov 13, 2019

Bug: Notebook Editor, Interactive Window, Python Editor cells

Steps to cause the bug to occur

  1. In the editor, have this code:
#%%
    a = 1
  1. Run the "Debug cell" action on the above cell.

Actual & Expected behavior

The result cell in the Python Interactive window:

breakpoint()
    a = 1

  File "", line 2
    a = 1
    ^
IndentationError: unexpected indent

Expected behavior is for this to work (despite the indentation of the code in the cell). Indeed, running the "Run Cell" action actually works well! This is extremely useful working with hybrid code/notebook files. So sometimes you have in a code.py file for instance:

def some_func():
    a = 1
    b = a + 1
    return b

and you want to work in the inside of the function interactively so you would make it:

#%%
def some_func():
#%%
    a = 1
    b = a + 1
#%%
    return b

That would make it possible to either call the code as the function or work on the contents interactively by evaluating/debugging the middle cell - extremely useful. I'm guessing this has to do with the breakpoint() statement added by the extension when "Debugging" cells.

Your Jupyter and/or Python environment

  • Jupyter server running: Local
  • Extension version: 2019.10.44104
  • VS Code version: 1.40.0
  • Setting python.jediEnabled: true
  • Python and/or Anaconda version: 3.5.4
  • OS: Windows
  • Virtual environment: pipenv

Possibly related microsoft/vscode-python#6680

@rchiodo
Copy link
Contributor

rchiodo commented Nov 21, 2019

Yes the breakpoint statement is breaking this. I believe we'd have to indent it as well.

@syagev
Copy link
Author

syagev commented Mar 30, 2020

There seems to be a slight regression on this issue. As a workaround I used to be able to manually attach to the kernel, set breakpoints, and then use CTRL+ENTER on cells and achieve similar behaviour as the "Debug Cell" command, even when working with remote jupyter servers. In the latest release, once VSCode is in debug mode after attaching, running CTRL+ENTER on cells results in the same IndentationError: unexpected indent as before (however, the breakpoint() statement itself is not seen anymore).

I believe that if my code is indented that leaves me unable to debug cells with remote kernels - since as far as I understand using the regular "Debug Cell" command is not supported with remote kernels. Any idea for another workaround involving indented code?

@rchiodo
Copy link
Contributor

rchiodo commented Mar 30, 2020

The breakpoint statement is still sent, you just can't see it anymore (we fixed a bug with computing hash value for the entered text).

However you should be turn off the first breakpoint with this setting:
"python.dataScience.stopOnFirstLineWhileDebugging"

That means we won't break on enter for a cell. So you'll have to put your own breakpoints.

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Dec 13, 2023

Thank you for filing this bug, given taht we haven't had enough users report this bug and the fact taht its more of an edge case, with only 3 users reporting this in the past 4 years, I'm closing this for now as wont fix.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug interactive-window-debugging
Projects
None yet
Development

No branches or pull requests

6 participants