Skip to content

IDLE and the interactive interpreter both wrongly reports a SyntaxError if no blank line after function definition. #93307

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

Closed
stevendaprano opened this issue May 28, 2022 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@stevendaprano
Copy link
Member

stevendaprano commented May 28, 2022

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 noblank.txt to noblank.py. (Github will not allow you to upload .py files!)

Run the renamed noblank.py file from the command line, e.g. python3.10 noblank.py. Note that it will run correctly from the vanilla Python interpreter. But it fails if copied and pasted into the interactive interpreter or IDLE.

Steps to reproduce

  1. Launch IDLE, or the CPython interactive interpreter.
  2. Copy the contents of noblank.py using your preferred text editor.
  3. Paste it at the >>> prompt.
  4. The interactive interpreter and IDLE both report a syntax error: SyntaxError: invalid syntax.

Expected behaviour

Preferably, the code should run and print "no blank" as it does in the non-interactive interpreter. If that is not possible, it should report a better error message, such as mentioning an unexpected outdent and suggesting that a blank line should be inserted.

  • CPython versions tested on: 3.10 on Linux.

noblank.txt

@aroberge
Copy link

This seems to be a bug in the code module, and not in IDLE per se.

>>> import code
>>> code.interact()
Python 3.10.2 ...
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> def noblank():
...     print("no blank")
... noblank()  # No blank line.
  File "<console>", line 3
    noblank()  # No blank line.
    ^^^^^^^
SyntaxError: invalid syntax

Tested in 3.6 to 3.11, and always got the same traceback.

@terryjreedy
Copy link
Member

(Stephen, please don't put 3 line examples in a separate file. Use a triple-backquoted block like Andre' did.)

In interactive mode, one must enter a single statement for each primary prompt. The example has 2 statements. Compound statements must be terminated with a blank. From Tutorial 3.2: "When a compound statement is entered interactively, it must be followed by a blank line to indicate completion (since the parser cannot guess when you have typed the last line)." The error is correct.

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2022
@erlend-aasland erlend-aasland moved this to Done in IDLE Issues Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

4 participants