You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code and IDLE should catch all compile errors. #69919
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/terryjreedy'closed_at=Nonecreated_at=<Date2015-11-25.14:26:38.301>labels= ['expert-IDLE', 'type-bug', 'library', '3.9']
title='Code and IDLE should catch all compile errors.'updated_at=<Date2019-09-20.21:08:22.670>user='https://github.com/pppery'
fails to compile with SystemError: too many statically nested blocks when typed in the standard interpreter.
When typed in an IDLE shell , pressing enter will not try to run the code, instead printing the SystemError to the console from which idle was started, instead of to the IDLE shell, which would be expected.
and editor code is compiled in ScriptBinding.py, line 100
try:
# If successful, return the compiled codereturncompile(source, filename, "exec")
except (SyntaxError, OverflowError, ValueError) asvalue:
Adding SystemError to the tuple is trivial. I just need to test to verify. (Side note: I think the tuple should be the same for both. The reasons for entries other than SyntaxError should be documented. ValueError when compiling?)
I believe that interactive input is forwarded to stdlib code.InteractiveInterpreter in PyShell.py, line 679
try:
# InteractiveInterpreter.runsource() calls its runcode() method,# which is overridden (see below)returnInteractiveInterpreter.runsource(self, source, filename)
The compile call and error catching is inside Lib/code.py, line 57.
Still relevant: compile() raises MemoryError or RecursionError for too deeply nested source, and a UnicodeEncodeError for surrogates; code, the REPL and IDLE catch only SyntaxError, OverflowError and ValueError, so IDLE's Shell gets stuck on such input. Two alternative fixes: #157585 makes them catch all exceptions (backportable), #157586 makes compile() raise SyntaxError in all these cases (main only).
Activity
pppery commentedon Nov 25, 2015
The following code:
fails to compile with
SystemError: too many statically nested blockswhen typed in the standard interpreter.When typed in an IDLE shell , pressing enter will not try to run the code, instead printing the SystemError to the console from which idle was started, instead of to the IDLE shell, which would be expected.
terryjreedy commentedon Nov 27, 2015
I believe startup files are compiled in PyShell.py, line 649 (3.x)
and editor code is compiled in ScriptBinding.py, line 100
Adding SystemError to the tuple is trivial. I just need to test to verify. (Side note: I think the tuple should be the same for both. The reasons for entries other than SyntaxError should be documented. ValueError when compiling?)
I believe that interactive input is forwarded to stdlib code.InteractiveInterpreter in PyShell.py, line 679
The compile call and error catching is inside Lib/code.py, line 57.
It should be fixed here.
pppery commentedon Nov 27, 2015
A similar problem occurs with the TypeError produced by attempting to compile a null byte.
terryjreedy commentedon Nov 27, 2015
How lovely ;-)
I almost think the long tuple should be replaced by Exception.
pppery commentedon Nov 27, 2015
Why does compile not support null bytes in the first place?
terryjreedy commentedon Jun 11, 2016
How to cause
SyntaxError -- obvious
NameError -- ?, already caught in code module
OverflowError-- ?, already caught in code module
SystemError - 22 nested for loops ('deeply nested blocks')
TypeError -- chr(0), 2.7
ValueError -- chr(0), 3.x; bytes(0), 2.7
[-]Idle does not handle non-standard compile errors[/-][+]Code and IDLE should catch all compile errors.[/+]serhiy-storchaka commentedon Jun 11, 2016
SystemError is serious bug. Please open separate issue for this.
Due to implementation detail of CPython tokenizer. I uses NUL-terminated C strings.
Yet one possible exception: MemoryError. I agree that the long tuple should be replaced by Exception.
pppery commentedon Jun 11, 2016
OverflowError is raised when one attempts to compile a string of 2**31 or more characters.
1 remaining item
pppery commentedon Jul 14, 2016
Done. I created bpo-27514
serhiy-storchaka commentedon Sep 15, 2026
Still relevant:
compile()raisesMemoryErrororRecursionErrorfor too deeply nested source, and aUnicodeEncodeErrorfor surrogates;code, the REPL and IDLE catch onlySyntaxError,OverflowErrorandValueError, so IDLE's Shell gets stuck on such input. Two alternative fixes: #157585 makes them catch all exceptions (backportable), #157586 makescompile()raiseSyntaxErrorin all these cases (main only).terryjreedy commentedon Sep 15, 2026
I would like to have both applied.
gh-69919: Catch all compile errors in the code module, pyrepl and IDLE (
[3.13] gh-69919: Catch all compile errors in the code module, pyrepl …
[3.14] gh-69919: Catch all compile errors in the code module, pyrepl …
[3.15] gh-69919: Catch all compile errors in the code module, pyrepl …