Skip to content

Compiler RecursionError more likely to occur in 3.13 #120331

Open
@williamwen42

Description

@williamwen42

Bug report

Bug description:

Reference: sympy/sympy#26692

There's a long expression in sympy that's causing a RecursionError in ast.c. The source of the RecursionError is

PyErr_SetString(PyExc_RecursionError,
.

This seems to happen with a 3.13 debug build due to a lower recursion limit. The error doesn't happen in 3.13 release.

Interestingly, the error doesn't happen in the 3.12 debug build, even though the recursion limit appears to be the same. This leads me to believe that 3.13 is causing more recursive calls than expected. I think we should investigate why 3.13 is making additional calls and/or raise the recursion limit.

Simple repro:

import ast
contents = "x = " + " * ".join(["1"] * 2000)
result = ast.parse(contents)

On 3.12 debug, this code runs fine. On 3.13 debug, this code causes a RecursionError even when we change 2000 to 500 (leading me to believe that it is not the case that 3.13 is just adding a constant number of additional calls).

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions