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.

Send to Interactive doesn't correctly handle indented code and comments

See original GitHub issue

Highlighting 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 image or image

Now send it to interactive.

>>>     y = 1
  File "<stdin>", line 1
    y = 1
    ^
IndentationError: unexpected indent

Now highlight the comment and z-line: image

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 image

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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RaymonGulati1commented, Jun 7, 2019

@joseortiz3, thank you for reporting this issue. I’m going to take a look at it.

0reactions
joseortiz3commented, Nov 22, 2019

I don’t think the current behavior is expected behavior. Handling indentation should be smarter than that.

Read more comments on GitHub >

github_iconTop 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 >

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