Skip to content

Run Selection/Line in Python Terminal gives syntax errors when running selection with function def or other blocks #259

Description

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

image

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:

  • Set Python as default interpreter
  • Execute any of the sample blocks by "Run Selection/Line command"

Logs

Output from Python Terminal
image
image

Activity

  1. ericsnowcurrently commented on Jan 18, 2018

    @ericsnowcurrently

    Hi Arundeep Singh (@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!

  2. tebeka commented on Jan 23, 2018

    @tebeka

    I'm hitting this problem as well, would love to see it solved.

  3. tebeka commented on Jan 24, 2018

    @tebeka

    From what I can see codeExectuor is calling normalizeLines which removes empty lines.

    IMO we can drop the call to normalizeLines and it'll work. Any ideas?

  4. tebeka commented on Jan 29, 2018

    @tebeka

    IMO this was fixed in ad806fa (by Don Jayamanne (@DonJayamanne)), is there a release planned soon?

  5. brettcannon commented on Jan 29, 2018

    @brettcannon
    Member

    Miki Tebeka (@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.

  6. tebeka commented on Jan 29, 2018

    @tebeka

    I've linked the current source tree (at 36b3050) to ~/.vscode/extension/vscode-pytho and tried the code - it worked.

    If you prefer I'll check an exact versionn please LMK which one and I'll check.

  7. brettcannon commented on Jan 29, 2018

    @brettcannon
    Member

    Nope, that does it! Thanks for the validation!

  8. 12 remaining items

  9. DonJayamanne commented on Apr 19, 2018

    @DonJayamanne

    Brett Cannon (@brettcannon)

    Looks like blank lines within a block of code (if, while, for) needs to be stripped off or we should indent accordingly).
    Each block of code should be separated with a blank line (i.e. different blocks of code should be separated with blank lines).

    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 4 spaces in this case).

    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

  10. brettcannon commented on Apr 19, 2018

    @brettcannon
    Member

    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. 😉

  11. added a commit that references this issue on Apr 23, 2018
    55f5ca5
  12. added a commit that references this issue on Apr 27, 2018
  13. added a commit that references this issue on Apr 30, 2018
    da91e3f
  14. locked as resolved and limited conversation to collaborators on Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-terminalbugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions