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

Python Run selection/Line In Python Terminal error - IndentationError: unexpected indent #2871

Closed
mdapri opened this issue Oct 12, 2018 · 1 comment

Comments

@mdapri
Copy link

mdapri commented Oct 12, 2018

Environment data

  • VS Code version: 1.28.1
  • Extension version (available under the Extensions sidebar): 2018.9.0 (9 Oct 2018)
  • OS and version: Windows 10 Enterprise
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32.
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): Miniconda, conda 4.5.11
  • Relevant/affected Python packages and their versions: NA

Actual behavior

Selecting the function definition in the code below (all the rows before v = add(1, 7))

def add(x, y):
    """Adds x to y"""
    # Some comment
    return x + y

v = add(1, 7)
print(v)

and running "Run Selection/Line in Python Terminal" [ / python.execSelectionInTerminal ] produces an error. Please note that there are no blank lines within function definition and there is a final blank line after the 'return x+y' statement

Expected behavior

The behavior is fine when saving the code above in a file "test_indent.py" and executing via command prompt
python test_indent.py
the result is
8

Steps to reproduce:

  1. create a new file in Visual Studio code
  2. Copy the code above
  3. Select all the lines of function definition
  4. "Run Selection/Line in Python Terminal" with right click option or Shift+Enter shortcut

Logs

Output for Python in the Terminal Window

>> def add(x, y):
...
  File "<stdin>", line 2

    ^
IndentationError: expected an indented block
>>>     """Adds x to y"""
  File "<stdin>", line 1
    """Adds x to y"""
    ^
IndentationError: unexpected indent
>>>
>>>     # Some comment
...
>>>     return x + y
  File "<stdin>", line 1
    return x + y
    ^
IndentationError: unexpected indent
@DonJayamanne
Copy link

Duplicate of #2857

@DonJayamanne DonJayamanne marked this as a duplicate of #2857 Oct 12, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Nov 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants