Send to Interactive doesn't correctly handle indented code and comments
See original GitHub issueHighlighting code and hitting “Send it to Interactive” is an extremely important feature to have working robustly.
However, the handling of indentation is extremely buggy.
One of the easiest demonstrations is the following: put this in a python script
def something_that_has_indented_code():
x = 1
y = 1
# A comment
z = 3
return
now highlight starting from the line above y=1
to the end of the line y=1
. You’ll get randomly either
or
Now send it to interactive.
>>> y = 1
File "<stdin>", line 1
y = 1
^
IndentationError: unexpected indent
Now highlight the comment and z-line:
Send to interactive
>>> # A comment
... z = 3
...
File "<stdin>", line 2
z = 3
^
IndentationError: unexpected indent
Loops don’t execute properly because of indentation handling. Test code:
def something_that_has_indented_code():
x = 1
y = 1
# A comment
z = 3
while(True):
if x == 10:
raise Exception('paste fail')
break
# this is a comment
x = x + 1
bob = 'bob'
# ------ Hello ------ #
# some comment
# another
print('Counter is %s' % x)
if x == 4:
break
a = 2
highlight the following
Send to interactive
>>> x = 1
>>> y = 1
>>> # A comment
... z = 3
...
>>> while(True):
... if x == 10:
... raise Exception('paste fail')
... break
... # this is a comment
... x = x + 1
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
Exception: paste fail
>>> bob = 'bob'
>>> # ------ Hello ------ #
...
...
... # some comment
... # another
... print('Counter is %s' % x)
...
Counter is 10
>>> if x == 4:
...
File "<stdin>", line 2
^
SyntaxError: unexpected EOF while parsing
>>> break
File "<stdin>", line 1
SyntaxError: 'break' outside loop
>>> a = 2
>>>
All of this demo was in VS 2019 16.1.0 preview 2.0. These problems are very old (years).
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
unexpected indent" when evaluating indented blocks of ...
Hello, I code in Spyder and PyCharm and both accept by default sending indented code to the console/interactive window and long as it's...
Read more >I can't post my question because of the "indentation"! How ...
I entered over 100 lines of code for my question, and then pressed "Submit" on Stack Overflow. The website gave me an error,...
Read more >How to fix Python indentation
Try IDLE, and use Alt + X to find indentation. It can automatically reformat the whole project or check if the project has...
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 >Python interactive window (REPL) - Visual Studio
Use the interactive window (REPL) for rapid Python code development in Visual Studio.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@joseortiz3, thank you for reporting this issue. I’m going to take a look at it.
I don’t think the current behavior is expected behavior. Handling indentation should be smarter than that.