Bound AST depth before the type checker walks it
With type checking on, a flat source that ruff parses into a very deep AST (a long + chain, attribute chain or A | B | ... annotation) passes the pre-parse nesting scan and then overflows the stack in ty, aborting the worker.
x = 1+1+1+...+1 # 20,000 terms: SyntaxError without type checking, stack overflow with it
Before ty runs, the worker, the stubs check on Configure and monty -t now walk the AST (string annotations included) with a depth-capped visitor and raise the compiler's SyntaxError: Source is too deeply nested past MAX_NESTING_DEPTH.
š¤ Generated with Claude Code
Summary by cubic
Fixes a stack overflow in the type checker when a flat source parses into a very deep AST (a long + chain, attribute chain, or A | B | ... annotation). These sources previously passed the pre-parse nesting scan and aborted the worker; they are now rejected with SyntaxError: Source is too deeply nested before type checking runs.
- The new
type_check_nesting_exceptionwalks the parsed AST, string annotations included, againstMAX_NESTING_DEPTH. - Worker feeds and stubs and the CLI's
-tall go through it. - The rejection covers annotations the compiler drops unchecked, so
def f(a: A | B | ...)is rejected only when type checking is on.