Message388174
#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? |
|
Date |
User |
Action |
Args |
2021-03-06 00:43:53 | terry.reedy | set | recipients:
+ terry.reedy, gvanrossum, aroberge, pablogsal |
2021-03-06 00:43:53 | terry.reedy | set | messageid: <1614991433.46.0.0299583371152.issue43366@roundup.psfhosted.org> |
2021-03-06 00:43:53 | terry.reedy | link | issue43366 messages |
2021-03-06 00:43:51 | terry.reedy | create | |
|