File tree Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -2120,13 +2120,21 @@ def set_recursion_limit(limit):
21202120 finally :
21212121 sys .setrecursionlimit (original_limit )
21222122
2123- def infinite_recursion (max_depth = 100 ):
2123+ def infinite_recursion (max_depth = None ):
21242124 """Set a lower limit for tests that interact with infinite recursions
21252125 (e.g test_ast.ASTHelpers_Test.test_recursion_direct) since on some
21262126 debug windows builds, due to not enough functions being inlined the
21272127 stack size might not handle the default recursion limit (1000). See
21282128 bpo-11105 for details."""
2129- if max_depth < 3 :
2129+ if max_depth is None :
2130+ if not python_is_optimized () or Py_DEBUG :
2131+ # Python built without compiler optimizations or in debug mode
2132+ # usually consumes more stack memory per function call.
2133+ # Unoptimized number based on what works under a WASI debug build.
2134+ max_depth = 50
2135+ else :
2136+ max_depth = 100
2137+ elif max_depth < 3 :
21302138 raise ValueError ("max_depth must be at least 3, got {max_depth}" )
21312139 depth = get_recursion_depth ()
21322140 depth = max (depth - 1 , 1 ) # Ignore infinite_recursion() frame.
Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ def do(bad):
221221 self .assertRaises (Exc , func , Bad ())
222222
223223 @support .no_tracing
224- @support .infinite_recursion (25 )
224+ @support .infinite_recursion ()
225225 def test_recursion (self ):
226226 # Check that comparison for recursive objects fails gracefully
227227 from collections import UserList
Original file line number Diff line number Diff line change @@ -5621,7 +5621,7 @@ def fun(x: a): pass
56215621 def cmp (o1 , o2 ):
56225622 return o1 == o2
56235623
5624- with infinite_recursion (25 ): # magic number, small but reasonable
5624+ with infinite_recursion ():
56255625 r1 = namespace1 ()
56265626 r2 = namespace2 ()
56275627 self .assertIsNot (r1 , r2 )
Original file line number Diff line number Diff line change 1+ Make the default value of ``test.support.infinite_recursion() `` to be
2+ conditional based on whether optimizations were used when compiling the
3+ interpreter. This helps with platforms like WASI whose stack size is greatly
4+ restricted in debug builds.
You can’t perform that action at this time.
0 commit comments