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 Selected Text in Active Terminal gives IndentationError with IPython

See original GitHub issue

Environment data

  • VS Code version: 1.40.2
  • Extension version (available under the Extensions sidebar): 2019.11.50794
  • OS and version: macOS Catalina 10.15.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.5 Anaconda defaults
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Relevant/affected Python packages and their versions: XXX
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): Language Server

Expected behaviour

Selecting some text and running the command “Terminal: Run Selected Text In Active Terminal” properly pastes the selection to an IPython console.

Actual behaviour

IndentationError is received.

Steps to reproduce:

  1. Launch IPython in the built-in terminal. Then open some file in the editor; type and select
for x in range(3):
    print(x)
    break
  1. Execute the command “Terminal: Run Selected Text in Active Terminal”

The following error is received:

In [1]: for x in range(3): 
   ...:         print(x) 
   ...:             break                                                                              
  File "<ipython-input-1-6c59f84e067e>", line 3
    break
    ^
IndentationError: unexpected indent

Logs

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

No output

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

No output

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:9
  • Comments:29 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
nicks515commented, Sep 30, 2021

Try to toggle ipython’s %autoindent into OFF.

https://ipython.org/ipython-doc/3/interactive/reference.html#autoindent

Autoindent is ON by default, but it can cause problems with the pasting of multi-line indented code (the pasted code gets re-indented on each line). A magic function %autoindent allows you to toggle it on/off at runtime. You can also disable it permanently on in your ipython_config.py file (set TerminalInteractiveShell.autoindent=False).

The above is out of date, but useful. For ipython_config.py creation, refer to the latest ipython documentation link below. https://ipython.readthedocs.io/en/stable/config/intro.html#python-configuration-files

2reactions
ericsnowcurrentlycommented, Dec 10, 2019

Ah, thanks for the clarification. We’ll look into this further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What should I do with "Unexpected indent" in Python?
The issue I'm describing is caused by the Sublime Text editor. The same issue could be caused by other editors as well. Essentially,...
Read more >
How do i resolve the unexpected indent error in python
As the error message indicates, you have an unexpected indent error. This error occurs when a statement is unnecessarily indented or its ...
Read more >
Python IndentationError: unexpected indent Solution
The cause of the “IndentationError: unexpected indent” error is indenting your code too far, or using too many tabs and spaces to indent...
Read more >
Optimizing Jupyter Notebook: Tips, Tricks, and nbextensions
Ctrl + Enter run selected cells; Alt + Enter run the current cell, insert below; Ctrl + S save and checkpoint. Shortcuts when...
Read more >
Plotting and Programming in Python - Our Lessons
Practice closing and restarting the JupyterLab server. Key Points. Python scripts are plain text files. Use the Jupyter Notebook for editing and running...
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