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 terry.reedy
Recipients aroberge, gvanrossum, pablogsal, terry.reedy
Date 2021-03-06.00:43:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1614991433.46.0.0299583371152.issue43366@roundup.psfhosted.org>
In-reply-to
Content
#43163 was about the opposite problem of raising SyntaxError too soon, when a valid continuation to imcomplete code is possible.  As with that issue, IDLE has the same problem, which is not in code.interact() itself but in codeop._maybe_compile.. 

Calling compile with, gives message, resulting in user seeing
'[def'                unclosed [      
'[def\n'              bad syntax     Syntax Error
'[\ndef'              unclosed [
'[\ndef\n'            unclosed [     prompt for more input

In the last line, the added \n after [ changes the compile SyntaxError message and, after PR 24483 for #43163, results in fruitlessly waiting for non-existent correct input until the user enters garbage or hits ^C. This is at best a codeop-specific regression from better behavior in 3.9

Changing 'def' to 'def f():' only changes the first message to 'invalid syntax' but not the user-visible result.

As near as I can tell, compile('[\n1,', ...) and compile('[\ndef', ...) give the same unclosed message pointing to the opening [.  How does the regular REPL know to prompt for input for the first and raise SyntaxError for the second?  Some unobvious flag combination?  (It is not 'exec' versus 'single'.)

>>> [
... 1,
... def
  File "<stdin>", line 3
    def
    ^
SyntaxError: invalid syntax

Guido, do you have any idea how python decides this or where the code is or who might know better?
History
Date User Action Args
2021-03-06 00:43:53terry.reedysetrecipients: + terry.reedy, gvanrossum, aroberge, pablogsal
2021-03-06 00:43:53terry.reedysetmessageid: <1614991433.46.0.0299583371152.issue43366@roundup.psfhosted.org>
2021-03-06 00:43:53terry.reedylinkissue43366 messages
2021-03-06 00:43:51terry.reedycreate