Skip to content

Commit e09ed54

Browse files
committed
make too many nested blocks be a SyntaxError instead of a SystemError (closes #27514)
Patch by Ammar Askar.
1 parent 2b87921 commit e09ed54

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Lib/test/test_syntax.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@
342342
...
343343
SyntaxError: 'break' outside loop
344344
345-
This should probably raise a better error than a SystemError (or none at all).
345+
This raises a SyntaxError, it used to raise a SystemError.
346+
Context for this change can be found on issue #27514
347+
346348
In 2.5 there was a missing exception and an assert was triggered in a debug
347349
build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514
348350
@@ -370,7 +372,7 @@
370372
... break
371373
Traceback (most recent call last):
372374
...
373-
SystemError: too many statically nested blocks
375+
SyntaxError: too many statically nested blocks
374376
375377
Misuse of the nonlocal statement can lead to a few unique syntax errors.
376378

Misc/NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27514: Make having too many statically nested blocks a SyntaxError
14+
instead of SystemError.
15+
1316
- Issue #27473: Fixed possible integer overflow in bytes and bytearray
1417
concatenations. Patch by Xiang Zhang.
1518

Python/compile.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3980,7 +3980,7 @@ compiler_push_fblock(struct compiler *c, enum fblocktype t, basicblock *b)
39803980
{
39813981
struct fblockinfo *f;
39823982
if (c->u->u_nfblocks >= CO_MAXBLOCKS) {
3983-
PyErr_SetString(PyExc_SystemError,
3983+
PyErr_SetString(PyExc_SyntaxError,
39843984
"too many statically nested blocks");
39853985
return 0;
39863986
}

0 commit comments

Comments
 (0)