Compiler RecursionError more likely to occur in 3.13
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 3.12 和 3.13 的 debug 构建中使用 ast.parse 重现该表达式,然后检查 Python/ast.c 中报告的第 217 行附近的递归检查。确定 3.13 为什么会进行额外的递归调用,或者递归限制是否不恰当;完成的标准是解决该回归问题,并验证所提供的重现不再失败。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 32/100