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

IDLE wrongly gives a syntax error when pasting code #93308

Closed
stevendaprano opened this issue May 28, 2022 · 1 comment
Closed

IDLE wrongly gives a syntax error when pasting code #93308

stevendaprano opened this issue May 28, 2022 · 1 comment
Labels
topic-IDLE type-feature A feature request or enhancement

Comments

@stevendaprano
Copy link
Member

See discussion here. Note that the code sample sent by Ron was correctly formatted in email, but has lost all indentation in the Discuss website.

Rename the attached blank.txt to blank.py. (Github will not allow you to upload .py files!)

Run the renamed blank.py file from the command line, e.g. python3.10 blank.py. Note that it will run correctly from the vanilla Python interpreter.

Launch the CPython interactive interpreter (REPL). Copy and paste the contents of blank.py using the editor of your choice, and paste it into the REPL at the >>> prompt. Notice that the blank line after the function correctly resets the prompt and the code will correctly run.

Steps to reproduce

  1. Launch IDLE.
  2. Copy the contents of blank.py using your preferred text editor, including the blank line after the return, and the following outdented function call.
  3. Paste it at the >>> prompt.
  4. Note that, unlike the CPython REPL, the blank line does not reset the prompt to >>> but it remains the level 2 prompt ... instead.
  5. IDLE wrongly reports a syntax error: SyntaxError: invalid syntax.

Expected behaviour

The behaviour should match the CPython interactive interpreter, or at the very least, a better error message should be given. See also issue #93307

  • CPython versions tested on: 3.10 on Linux.

blank.txt

@stevendaprano stevendaprano added the type-bug An unexpected behavior, bug, or error label May 28, 2022
@terryjreedy terryjreedy added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Jul 23, 2022
@terryjreedy
Copy link
Member

The example, which should have been in the post:

def blank():
    print("blank")

blank()  # Blank line above this.

This feature change request is a duplicate of #47809 and possibly #51989. The REPL treats pasted text the same as entered text. Hence it feeds lines to python 1 at a time. Tcl/tk pastes the entire code into a text widget all at once. IDLE intentionally allows user to edit pasted code before submitting it for execution with . IDLE, via code.InteractiveInterpreter and codeop, compiles statements with compile(..., mode='single') and submits the returned code object for execution. Multiple statements are an error for 'single' mode.

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-IDLE type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants