MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / recursionlimit

Class recursionlimit

markdown/test_tools.py:91–116  ·  view source on GitHub ↗

A context manager which temporarily modifies the Python recursion limit. The testing framework, coverage, etc. may add an arbitrary number of levels to the depth. To maintain consistency in the tests, the current stack depth is determined when called, then added to the provided limit.

Source from the content-addressed store, hash-verified

89
90
91class recursionlimit:
92 """
93 A context manager which temporarily modifies the Python recursion limit.
94
95 The testing framework, coverage, etc. may add an arbitrary number of levels to the depth. To maintain consistency
96 in the tests, the current stack depth is determined when called, then added to the provided limit.
97
98 Example usage:
99
100 ``` python
101 with recursionlimit(20):
102 # test code here
103 ```
104
105 See <https://stackoverflow.com/a/50120316/866026>.
106 """
107
108 def __init__(self, limit):
109 self.limit = util._get_stack_depth() + limit
110 self.old_limit = sys.getrecursionlimit()
111
112 def __enter__(self):
113 sys.setrecursionlimit(self.limit)
114
115 def __exit__(self, type, value, tb):
116 sys.setrecursionlimit(self.old_limit)
117
118
119#########################

Callers 1

test_nesting_limitMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_nesting_limitMethod · 0.72