Skip to content

Commit eb263f9

Browse files
authored
bpo-25130: Make unit-test about restricting the maximum number of nested blocks cpython-only (GH-28002)
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.
1 parent 206b21e commit eb263f9

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

Lib/test/test_syntax.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -629,38 +629,6 @@
629629
...
630630
SyntaxError: 'break' outside loop
631631
632-
This raises a SyntaxError, it used to raise a SystemError.
633-
Context for this change can be found on issue #27514
634-
635-
In 2.5 there was a missing exception and an assert was triggered in a debug
636-
build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514
637-
638-
>>> while 1:
639-
... while 2:
640-
... while 3:
641-
... while 4:
642-
... while 5:
643-
... while 6:
644-
... while 8:
645-
... while 9:
646-
... while 10:
647-
... while 11:
648-
... while 12:
649-
... while 13:
650-
... while 14:
651-
... while 15:
652-
... while 16:
653-
... while 17:
654-
... while 18:
655-
... while 19:
656-
... while 20:
657-
... while 21:
658-
... while 22:
659-
... break
660-
Traceback (most recent call last):
661-
...
662-
SyntaxError: too many statically nested blocks
663-
664632
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
665633
666634
>>> def f():
@@ -1550,6 +1518,41 @@ def test_multiline_compiler_error_points_to_the_end(self):
15501518
lineno=3
15511519
)
15521520

1521+
@support.cpython_only
1522+
def test_syntax_error_on_deeply_nested_blocks(self):
1523+
# This raises a SyntaxError, it used to raise a SystemError. Context
1524+
# for this change can be found on issue #27514
1525+
1526+
# In 2.5 there was a missing exception and an assert was triggered in a
1527+
# debug build. The number of blocks must be greater than CO_MAXBLOCKS.
1528+
# SF #1565514
1529+
1530+
source = """
1531+
while 1:
1532+
while 2:
1533+
while 3:
1534+
while 4:
1535+
while 5:
1536+
while 6:
1537+
while 8:
1538+
while 9:
1539+
while 10:
1540+
while 11:
1541+
while 12:
1542+
while 13:
1543+
while 14:
1544+
while 15:
1545+
while 16:
1546+
while 17:
1547+
while 18:
1548+
while 19:
1549+
while 20:
1550+
while 21:
1551+
while 22:
1552+
break
1553+
"""
1554+
self._check_error(source, "too many statically nested blocks")
1555+
15531556

15541557
def test_main():
15551558
support.run_unittest(SyntaxTestCase)

0 commit comments

Comments
 (0)