Compiler RecursionError more likely to occur in 3.13
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Reference: https://github.com/sympy/sympy/issues/26692
There's a long expression in sympy that's causing a RecursionError in ast.c. The source of the RecursionError is https://github.com/python/cpython/blob/ffc8e21c80627c46be7a7467ee5427924fdeb885/Python/ast.c#L217.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the expression with ast.parse on 3.12 and 3.13 debug builds, then inspect Python/ast.c at the reported recursion check around line 217. Determine why 3.13 makes additional recursive calls or whether the recursion limit is inappropriate; done means resolving the regression and verifying the provided reproduction no longer fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100