python
system_error
ai_generated
true
递归错误:调用 Python 对象时超过最大递归深度
RecursionError: maximum recursion depth exceeded while calling a Python object
ID: python/recursionerror-maximum-recursion-depth
80%修复率
84%置信度
0证据数
2024-11-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
根因分析
测试函数或 fixture 在没有基本情况的情况下递归调用自身,或模拟设置导致无限递归。
English
A test function or fixture calls itself recursively without a base case, or a mock setup causes infinite recursion.
解决方案
-
95% 成功率 Add a base case to recursive function
def recursive_func(n): if n <= 0: return recursive_func(n-1) -
90% 成功率 Use iterative approach instead of recursion
def iterative_func(n): while n > 0: n -= 1
无效尝试
常见但无效的做法:
-
Increasing recursion limit with sys.setrecursionlimit
70% 失败
Postpones the problem; may cause stack overflow or crash.
-
Ignoring the error
90% 失败
The test will always fail until recursion is fixed.