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.

Run selection indentation error

See original GitHub issue

Environment data

  • VS Code version:
  • OS and version:

Version: 1.49.1 Commit: 58bb7b2331731bf72587010e943852e13e6fd3cf Date: 2020-09-16T23:21:17.533Z (6 days ago) Electron: 9.2.1 Chrome: 83.0.4103.122 Node.js: 12.14.1 V8: 8.3.110.13-electron.0 OS: Darwin x64 19.6.0

  • Extension version (available under the Extensions sidebar):

2020.8.1 (20 August 2020)

  • Python version (& distribution if applicable, e.g. Anaconda):

Python 3.7.8, Python 3.8.4

  • Type of virtual environment used (N/A | venv | virtualenv | conda | …):

venv, and without a virtual environment

  • Relevant/affected Python packages and their versions:

N/A

  • Relevant/affected Python-related VS Code extensions and their versions:

N/A

  • Value of the python.languageServer setting:

Pylance

[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]

Expected behaviour

When I highlight Python code and run selection I expect it to run if it is syntactically correct.

Actual behaviour

I’m receiving indentation errors in specific scenarios for code that is syntactically correct.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

Run selection on the following code and the following error(s) will occur

if False:
    print("if")
elif True:
    print("elif")
else:
    print("else")
if False:
...     print("if")
... 
>>> elif True:
  File "<stdin>", line 1
    elif True:
    ^
SyntaxError: invalid syntax
>>>     print("elif")
  File "<stdin>", line 1
    print("elif")
    ^
IndentationError: unexpected indent
>>> else:
  File "<stdin>", line 1
    else:
    ^
SyntaxError: invalid syntax
>>>     print("else")
  File "<stdin>", line 1
    print("else")
    ^
IndentationError: unexpected indent
>>>

If I copy/paste the same code into the Python interactive window it will run without error.

run_selection

Logs

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

User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'LocalZMQKernel - control'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - experiment'
User belongs to experiment group 'CustomEditorSupport - control'
User belongs to experiment group 'pythonaacf'
User belongs to experiment group 'pythonTipPromptWording'
> conda --version
> conda info --json
> pyenv root
> python3.7 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Error 2020-09-22 22:05:40: Failed to download and store experiments, Class name = b, completed in 528ms, has a falsy return value, , Return Value: undefined [Error: Failed with status 404, Not Found, Uri https://raw.githubusercontent.com/microsoft/vscode-python/master/experiments.json
	at H._callback (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/extension.js:54:716477)
	at H.a._callback.a.callback.a.callback (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/node_modules/request.js:189:5442)
	at H.emit (events.js:223:5)
	at H.<anonymous> (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/node_modules/request.js:189:18302)
	at H.emit (events.js:223:5)
	at IncomingMessage.<anonymous> (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/node_modules/request.js:189:17134)
	at Object.onceWrapper (events.js:312:28)
	at IncomingMessage.emit (events.js:228:7)
	at endReadableNT (_stream_readable.js:1185:12)
	at processTicksAndRejections (internal/process/task_queues.js:81:21)]
Error 2020-09-22 22:05:40: Failed to initialize experiments, Class name = b, completed in 535ms, has a falsy return value, , Return Value: undefined [Error: Failed with status 404, Not Found, Uri https://raw.githubusercontent.com/microsoft/vscode-python/master/experiments.json
	at H._callback (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/extension.js:54:716477)
	at H.a._callback.a.callback.a.callback (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/node_modules/request.js:189:5442)
	at H.emit (events.js:223:5)
	at H.<anonymous> (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/node_modules/request.js:189:18302)
	at H.emit (events.js:223:5)
	at IncomingMessage.<anonymous> (/Users/dplumley/.vscode/extensions/ms-python.python-2020.9.106471-dev/out/client/node_modules/request.js:189:17134)
	at Object.onceWrapper (events.js:312:28)
	at IncomingMessage.emit (events.js:228:7)
	at endReadableNT (_stream_readable.js:1185:12)
	at processTicksAndRejections (internal/process/task_queues.js:81:21)] {
  vslsStack: [
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {},
    CallSite {}, CallSite {}
  ]
}
Python interpreter path: /usr/local/bin/python3
Starting Pylance language server.
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import jupyter"
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py -c "import notebook"
> conda --version
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/normalizeForInterpreter.py "if False:
    print("if")
elif True:
    print("elif")
else:
    print("else")"
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/normalizeForInterpreter.py "if False:
    print("if")
elif True:
    print("elif")
else:
    print("else")"
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/normalizeForInterpreter.py "if False:
    print("if")
elif True:
    print("elif")
else:
    print("else")"
> /usr/local/bin/python3 ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.9.106471-dev/pythonFiles/normalizeForInterpreter.py "if False:
    print("if")
elif True:
    print("elif")
else:
    print("else")"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
luabudcommented, Jan 22, 2021

This should be fixed on our newest release, version 2021.1.502429796, but if you’re still seeing this let us now 😊

0reactions
shun-intcommented, Oct 6, 2020

Nice. It helps a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indentation error when running python code in VS Code
In Visual Studio Code do CTRL + SHIFT + P and type in "indentation" ...
Read more >
Indentation Error in Python | How to Solve it - Edureka
This article will provide you with a detailed understanding of Indentation error in Python and the solutions to avoid the same.
Read more >
How to fix indentation Error in Python - Numpy Ninja
If you are new to coding or an experienced coder, you might have come across indentation error in python. It looks silly but...
Read more >
Indentation Error in Python: Causes, How to Solve, Benefits
Select your code and press Tab or Shift + Tab to indent or un-indent it. Other tools for altering your code can be...
Read more >
How does Indentation Error Work in Python? - eduCBA
It uses the PEP8 whitespace ethics. There should be 4 whitespaces used between any alternative or iteration. It happens mainly because of the...
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