summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index e9bec33..de783f7 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -2392,13 +2392,40 @@ if x:
code += "): yield a"
return code
- CO_MAXBLOCKS = 20 # static nesting limit of the compiler
+ CO_MAXBLOCKS = 21 # static nesting limit of the compiler
+ MAX_MANAGERS = CO_MAXBLOCKS - 1 # One for the StopIteration block
- for n in range(CO_MAXBLOCKS):
+ for n in range(MAX_MANAGERS):
with self.subTest(f"within range: {n=}"):
compile(get_code(n), "<string>", "exec")
- for n in range(CO_MAXBLOCKS, CO_MAXBLOCKS + 5):
+ for n in range(MAX_MANAGERS, MAX_MANAGERS + 5):
+ with self.subTest(f"out of range: {n=}"):
+ self._check_error(get_code(n), "too many statically nested blocks")
+
+ @support.cpython_only
+ def test_async_with_statement_many_context_managers(self):
+ # See gh-116767
+
+ def get_code(n):
+ code = [ textwrap.dedent("""
+ async def bug():
+ async with (
+ a
+ """) ]
+ for i in range(n):
+ code.append(f" as a{i}, a\n")
+ code.append("): yield a")
+ return "".join(code)
+
+ CO_MAXBLOCKS = 21 # static nesting limit of the compiler
+ MAX_MANAGERS = CO_MAXBLOCKS - 1 # One for the StopIteration block
+
+ for n in range(MAX_MANAGERS):
+ with self.subTest(f"within range: {n=}"):
+ compile(get_code(n), "<string>", "exec")
+
+ for n in range(MAX_MANAGERS, MAX_MANAGERS + 5):
with self.subTest(f"out of range: {n=}"):
self._check_error(get_code(n), "too many statically nested blocks")
@@ -2536,7 +2563,8 @@ while 1:
while 20:
while 21:
while 22:
- break
+ while 23:
+ break
"""
self._check_error(source, "too many statically nested blocks")