diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index ae3043af0bd2d4..29aa362590f75e 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -672,7 +672,7 @@ def __fspath__(self): compile("42", PathLike("test_compile_pathlike"), "single") -class TestStackSize(unittest.TestCase): +class TestExpressionStackSize(unittest.TestCase): # These tests check that the computed stack size for a code object # stays within reasonable bounds (see issue #21523 for an example # dysfunction). @@ -710,5 +710,294 @@ def test_func_and(self): self.check_stack_size(code) +class TestStackSizeStability(unittest.TestCase): + # Check that repeating certain snippets doesn't increase the stack size + # beyond what a single snippet requires. + + def check_stack_size(self, snippet, async_=False): + def compile_snippet(i): + ns = {} + script = """def func():\n""" + i * snippet + if async_: + script = "async " + script + code = compile(script, "