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
Parsing deeply-nested Python source (brackets, parens, etc.) crashes the interpreter with SIGSEGV at ~4000 levels of nesting. CPython caps this at 200 via SyntaxError: too many nested parentheses from the parser's internal depth limit.
The crash is in the parser itself (rustpython-ruff_python_parser 0.15.8): compile(src, '<s>', 'exec') (parser + codegen, does NOT go through _ast::ast_to_object) and ast.parse() crash at the identical depth threshold, showing the shared component is the parser, not post-parse conversion.
This is the parser-layer root cause of the class of bugs tracked in #2796. #4857 also still reproduces on current main (closed as fixed in 2023).
Expected
Matches CPython 3.13.4 behavior:
$ python3 -c "import ast; ast.parse('[' * 5000 + '1' + ']' * 5000)"
Traceback (most recent call last):
...
SyntaxError: too many nested parentheses (<unknown>, line 1)
(CPython's parser rejects at depth 201 via a hard-coded limit, well before the native stack is exhausted.)
Both fixes live downstream of the parser. The parser's own recursive descent has no depth guard, so any Python source deeply nested in brackets, parens, unary ops, or binary ops reaches the native stack limit first.
Environment
RustPython main @ 5a45d41d (parser: rustpython-ruff_python_parser 0.15.8)
Activity
sigmaith commentedon Aug 17, 2026
take
Bound AST nesting so deep source raises instead of crashing (RustPyth…