Guido van Rossum <> added the comment:

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

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 

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 


Python tracker <>
Python-bugs-list mailing list

Reply via email to