This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients Phaqui, gvanrossum, terry.reedy
Date 2019-11-11.04:11:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1573445471.08.0.215760493248.issue38673@roundup.psfhosted.org>
In-reply-to
Content
> But is the 'fix' in _maybe_compile at all applicable to the REPL?  Or might a parser change REPL fix make the code in _maybe_compile unneeded?

I don't know.  Most of the contortions in code.py codeop.py are meant to emulate what the parser does without help in the REPL: keep asking for input until one of the following happens:

- a syntax error is found;

- a simple statement is parsed till completion;

- an empty line is found at a point where a compound statement is potentially complete.

The bug here is that apparently the above conditions aren't quite enough, and it seems we need to add:

- a line that contains just whitespace and/or a comment is seen before anything else.

The reason that IDLE has to reimplement similar logic is that the parser (actually, the tokenizer) isn't written as a coroutine to which you send lines you read -- it's written as a blocking function that you pass a file and the function will attempt to read lines from the file.  The function returns a parse tree or raise an error.  That model doesn't work in IDLE, which needs to stay reactive while the shell window is in the middle of a statement.

I think we'll find that the bug is *very* old.  IIRC the initial releases of Python didn't have the rule that indentation is ignored between matching parentheses/brackets/braces.  In those days the tokenizer also didn't gracefully skip blank lines, or lines with comments that weren't aligned with the current indentation level.  So then checking for empty lines was good enough.
History
Date User Action Args
2019-11-11 04:11:11gvanrossumsetrecipients: + gvanrossum, terry.reedy, Phaqui
2019-11-11 04:11:11gvanrossumsetmessageid: <1573445471.08.0.215760493248.issue38673@roundup.psfhosted.org>
2019-11-11 04:11:11gvanrossumlinkissue38673 messages
2019-11-11 04:11:10gvanrossumcreate