-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Run Selection/Line in Python Terminal gives syntax errors when running selection with function def or other blocks #259
Comments
Hi @arundeep78! Thanks for letting us know about this issue. I've been able to reproduce the problem (at least under linux). It appears to be related to the blank lines getting dropped somewhere along the line. We'll look into it as soon as we can. Thanks again! |
I'm hitting this problem as well, would love to see it solved. |
From what I can see IMO we can drop the call to |
IMO this was fixed in ad806fa (by @DonJayamanne), is there a release planned soon? |
@tebeka we're hoping to release this week. If you want to help us validate that this got fixed, please install an insiders build and let us know if your issue was fixed. |
I've linked the current source tree (at 36b3050) to If you prefer I'll check an exact versionn please LMK which one and I'll check. |
Nope, that does it! Thanks for the validation! |
Seems like if there are empty lines inside a function this still happens. I tried the below code with the new release and still get indentation error. test.pydef add(x, y):
"""Adds x to y"""
# Some comment
return x + y
v = add(1, 7)
print(v) terminal output
|
Reopening as this issue was never fixed, i obviously made a mistake in closing this. |
Looks like blank lines within a block of code (if, while, for) needs to be stripped off or we should indent accordingly). Sample 1 if True:
print(1)
print(2) In order to get the above working in the terminal, we should either strip the blank line between the two print statements or ensure the blank line is indented (i.e. has Sample 2 if True:
print(1)
print(2)
print(3) For this code to work in the terminal, there must be a blank line between the last two print statements. I.e. we need a blank line to separate the if block from the rest of the code. More information here https://stackoverflow.com/questions/8391633/blank-line-rule-at-interactive-prompt |
Either the leading newlines prepended to blank lines or stripping them are fine by me (I guess the blank prepending will lead to less surprise for people when looking at the REPL, but debugging that later will be a nightmare for any bug reports). As for inserting the newline between blocks, we can't solve all problems at once. 😉 |
Environment data
VS Code version: 1.18.0
Python Extension version: 0.8.0
Python Version: 3.6.2 :: Continuum Analytics, Inc./ 2.7.13 :: Anaconda 4.4.0 (x86_64)
OS and version: OSX El Capitan 10.11.6
Actual behavior
Tries to execute a block and gives a syntax error
However, while executing those block as individual blocks. e.g. def separate and print separate it works fine.
Expected behavior
It should execute the whole selection without issues.
Steps to reproduce:
Logs
Output from
Python
TerminalThe text was updated successfully, but these errors were encountered: