question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

first no results, then "IndentationError: unexpected indent" when starting commands with an indented block with shift+Enter

See original GitHub issue

Environment data

Version: 1.46.1 (user setup) Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d Date: 2020-06-17T21:16:50.293Z Electron: 7.3.1 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT ia32 10.0.18363

  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): None
  • Relevant/affected Python packages and their versions: all
  • Relevant/affected Python-related VS Code extensions and their versions: all
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

if True:
    print('Hello')

–> Hello

Actual behaviour

>>> if True:
...     print('Hello')
... if True:
  File "<stdin>", line 3
    if True:
    ^
SyntaxError: invalid syntax
>>>     print('Hello')
  File "<stdin>", line 1
    print('Hello')
    ^

IndentationError: unexpected indent
>>> 

running only the isolated print('Hello') line without the if True prints the expected “Hello”, regardless of the indentation.

Steps to reproduce:

  1. run
if True:
    print('Hello')
  1. run
if True:
    print('Hello')
  1. / 4. you could repeat it, it would always give you just a print of your command at first, and at the second time it will give you IndentationError again.

To make this clear: I cannot run any indented code at all, whatever the example. Any line that is not indented inside a parent command can be run, and any line that I select as a single line can be run regardless of its indentation.

This error still occurs after using the repair function of Python 3.8.3 installation file.

This error does not occur when using the Python ide of Python 3.8.3 in command prompt --> python.exe.

I have already switched vscode settings between 4 spaces and tab indentation, and I have replaced tabs with 4 spaces in the whole file and back. Of course I have also restarted many times and I have opened completely new py files to check it again. I have also installed vscode over the current vscode installation, no change. Then I have uninstalled vscode and installed it again, no change. Then I have uninstalled both vscode and Python, restarted, and installed both again, no change.

probably linked with https://github.com/microsoft/vscode/issues/61092

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lorenzznerolcommented, Oct 24, 2021

Hi @karrtikr, I have tested this, there is no issue anymore.

bild

  • Windows 10
  • Python version: 3.8.8 (anaconda)
  • Python extension for Visual Studio Code: v2021.10.1365161279
0reactions
karrtikrcommented, Oct 22, 2021

Hi, is this still an issue with the latest version of the extension?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What should I do with "Unexpected indent" in Python?
print "hello" IndentationError: unexpected indent. Unindent does not match any outer indentation level. This line of code has fewer spaces at the start...
Read more >
How do i resolve the unexpected indent error in python
This error occurs when a statement is unnecessarily indented or its indentation does not match the indentation of former statements in the same ......
Read more >
Python IndentationError: unexpected indent Solution
We have incidentally indented the second print() statement. This causes an error because our second print() statement is not part of another ...
Read more >
How to fix indentation Error in Python - Numpy Ninja
Unexpected indent - This line of code has more spaces at the beginning than the one before it, but the one before it...
Read more >
What is unexpected indent in Python? - Net-Informations.Com
As the error message indicates, you have an indentation error . ... basic rule for indenting Python coding style is: The first statement...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found