python
system_error
ai_generated
true
RecursionError: maximum recursion depth exceeded while calling a Python object
ID: python/recursionerror-maximum-recursion-depth
80%Fix Rate
84%Confidence
0Evidence
2024-11-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
Root Cause
A test function or fixture calls itself recursively without a base case, or a mock setup causes infinite recursion.
generic中文
测试函数或 fixture 在没有基本情况的情况下递归调用自身,或模拟设置导致无限递归。
Workarounds
-
95% success Add a base case to recursive function
def recursive_func(n): if n <= 0: return recursive_func(n-1) -
90% success Use iterative approach instead of recursion
def iterative_func(n): while n > 0: n -= 1
Dead Ends
Common approaches that don't work:
-
Increasing recursion limit with sys.setrecursionlimit
70% fail
Postpones the problem; may cause stack overflow or crash.
-
Ignoring the error
90% fail
The test will always fail until recursion is fixed.