[Python-checkins] [3.9] bpo-25130: Make unit-test about restricting the maximum number of nested blocks cpython-only (GH-28002) (GH-28017)

serhiy-storchaka webhook-mailer at python.org
Sat Aug 28 15:24:43 EDT 2021


https://github.com/python/cpython/commit/1046cd06b0e2f20b3be93de83d49b684956af98d
commit: 1046cd06b0e2f20b3be93de83d49b684956af98d
branch: 3.9
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2021-08-28T22:24:39+03:00
summary:

[3.9] bpo-25130: Make unit-test about restricting the maximum number of nested blocks cpython-only (GH-28002) (GH-28017)

PyPy and potentially other implementations have different or no
contraints on the number of blocks that can be statically nested. move
the test that checks for this behaviour into a unit test and mark it as
CPython-only..
(cherry picked from commit eb263f9a356f5c5f21b8d5ce20bac92f31c40cad)

Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>

files:
M Lib/test/test_syntax.py

diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index f54b09f54f03d..eaa94ea92b5cd 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -531,38 +531,6 @@
      ...
    SyntaxError: 'break' outside loop
 
-This raises a SyntaxError, it used to raise a SystemError.
-Context for this change can be found on issue #27514
-
-In 2.5 there was a missing exception and an assert was triggered in a debug
-build.  The number of blocks must be greater than CO_MAXBLOCKS.  SF #1565514
-
-   >>> while 1:
-   ...  while 2:
-   ...   while 3:
-   ...    while 4:
-   ...     while 5:
-   ...      while 6:
-   ...       while 8:
-   ...        while 9:
-   ...         while 10:
-   ...          while 11:
-   ...           while 12:
-   ...            while 13:
-   ...             while 14:
-   ...              while 15:
-   ...               while 16:
-   ...                while 17:
-   ...                 while 18:
-   ...                  while 19:
-   ...                   while 20:
-   ...                    while 21:
-   ...                     while 22:
-   ...                      break
-   Traceback (most recent call last):
-     ...
-   SyntaxError: too many statically nested blocks
-
 Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
 
    >>> def f():
@@ -995,6 +963,42 @@ def test_invalid_line_continuation_left_recursive(self):
         self._check_error("A.\u03bc\\\n",
                           "unexpected EOF while parsing")
 
+    @support.cpython_only
+    def test_syntax_error_on_deeply_nested_blocks(self):
+        # This raises a SyntaxError, it used to raise a SystemError. Context
+        # for this change can be found on issue #27514
+
+        # In 2.5 there was a missing exception and an assert was triggered in a
+        # debug build.  The number of blocks must be greater than CO_MAXBLOCKS.
+        # SF #1565514
+
+        source = """
+while 1:
+ while 2:
+  while 3:
+   while 4:
+    while 5:
+     while 6:
+      while 8:
+       while 9:
+        while 10:
+         while 11:
+          while 12:
+           while 13:
+            while 14:
+             while 15:
+              while 16:
+               while 17:
+                while 18:
+                 while 19:
+                  while 20:
+                   while 21:
+                    while 22:
+                     break
+"""
+        self._check_error(source, "too many statically nested blocks")
+
+
 def test_main():
     support.run_unittest(SyntaxTestCase)
     from test import test_syntax



More information about the Python-checkins mailing list