gh-69919: Catch all compile errors in the code module, pyrepl and IDLE - #157585
Open
serhiy-storchaka wants to merge 3 commits into
Open
serhiy-storchaka wants to merge 3 commits into
serhiy-storchaka wants to merge 3 commits into
Conversation
…nd IDLE compile() can raise MemoryError or RecursionError for too deeply nested source, not only SyntaxError, OverflowError and ValueError. IDLE's Shell then lost its prompt until the input was deleted. Co-authored-by: Terry Jan Reedy <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
serhiy-storchaka
requested review from
ambv,
lysnikolaou,
pablogsal and
terryjreedy
as code owners
September 15, 2026 19:32
Documentation build overview
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
compile()can raise more thanSyntaxError,OverflowErrorandValueError:MemoryError("Parser stack overflowed") for a few thousand chained unary operators,RecursionError("Stack overflow during compilation") for tens of thousands of chained binary operators, and a bareMemoryErrorwhen memory really runs out.code.InteractiveInterpreter.runsource()let those propagate, socode.interact()died. The new REPL survives through its outer loop, but prints a bareMemoryErrorwithout the message, or aRecursionErrortraceback through its own internals. In IDLE's Shell the exception escaped into the Tk callback, no new prompt was issued, and the next Enter re-compiled the same text: the Shell was stuck until the input was deleted.Based on Terry's 2016 patch from the issue:
runsource()incodeand_pyrepl,_pyrepl's incomplete-input check, the startup-file compile inpyshell.py,runscript.checksyntax(), andpdb'sfind_function()and the check ofcondition/display/ignoreexpressions catchException. TheSyntaxError-specific code in IDLE (marking the position in the text) runs only forSyntaxError; other exceptions are reported through the base class, i.e. bytraceback. IDLE now also names the actual exception, so anIndentationErroris no longer reported asSyntaxError.The
compile()documentation now lists the exceptions it can raise (includingOverflowErrorfor a too large source), and notes the 3.12 change for null bytes fromValueErrortoSyntaxError.An alternative that fixes this in
compile()itself, for main only, is #157586.🤖 Generated with Claude Code