MCPcopy Index your code
hub / github.com/python/cpython / install_recursionlimit_wrappers

Function install_recursionlimit_wrappers

Lib/idlelib/run.py:347–384  ·  view source on GitHub ↗

Install wrappers to always add 30 to the recursion limit.

()

Source from the content-addressed store, hash-verified

345RECURSIONLIMIT_DELTA = 30
346
347def install_recursionlimit_wrappers():
348 """Install wrappers to always add 30 to the recursion limit."""
349 # see: bpo-26806
350
351 @functools.wraps(sys.setrecursionlimit)
352 def setrecursionlimit(*args, **kwargs):
353 # mimic the original sys.setrecursionlimit()'s input handling
354 if kwargs:
355 raise TypeError(
356 "setrecursionlimit() takes no keyword arguments")
357 try:
358 limit, = args
359 except ValueError:
360 raise TypeError(f"setrecursionlimit() takes exactly one "
361 f"argument ({len(args)} given)")
362 if not limit > 0:
363 raise ValueError(
364 "recursion limit must be greater or equal than 1")
365
366 return setrecursionlimit.__wrapped__(limit + RECURSIONLIMIT_DELTA)
367
368 fixdoc(setrecursionlimit, f"""\
369 This IDLE wrapper adds {RECURSIONLIMIT_DELTA} to prevent possible
370 uninterruptible loops.""")
371
372 @functools.wraps(sys.getrecursionlimit)
373 def getrecursionlimit():
374 return getrecursionlimit.__wrapped__() - RECURSIONLIMIT_DELTA
375
376 fixdoc(getrecursionlimit, f"""\
377 This IDLE wrapper subtracts {RECURSIONLIMIT_DELTA} to compensate
378 for the {RECURSIONLIMIT_DELTA} IDLE adds when setting the limit.""")
379
380 # add the delta to the default recursion limit, to compensate
381 sys.setrecursionlimit(sys.getrecursionlimit() + RECURSIONLIMIT_DELTA)
382
383 sys.setrecursionlimit = setrecursionlimit
384 sys.getrecursionlimit = getrecursionlimit
385
386
387def uninstall_recursionlimit_wrappers():

Callers 1

handleMethod · 0.85

Calls 1

fixdocFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…