diff -r 89821243621b Lib/test/test_syntax.py --- a/Lib/test/test_syntax.py Thu Jul 14 07:45:24 2016 +0300 +++ b/Lib/test/test_syntax.py Thu Jul 14 14:20:31 2016 -0700 @@ -334,9 +334,12 @@ ... SyntaxError: 'break' outside loop -This should probably raise a better error than a SystemError (or none at all). +This raises a SyntaxError, it used to raise a SystemError. +Context for this change: https://bugs.python.org/issue27514 + 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 +build. The number of blocks must be greater than CO_MAXBLOCKS. +SF #1565514 (https://mail.python.org/pipermail/python-bugs-list/2006-October/035880.html) >>> while 1: ... while 2: @@ -362,7 +365,7 @@ ... break Traceback (most recent call last): ... - SystemError: too many statically nested blocks + SyntaxError: too many statically nested blocks Misuse of the nonlocal statement can lead to a few unique syntax errors. diff -r 89821243621b Python/compile.c --- a/Python/compile.c Thu Jul 14 07:45:24 2016 +0300 +++ b/Python/compile.c Thu Jul 14 14:20:31 2016 -0700 @@ -4249,7 +4249,7 @@ { struct fblockinfo *f; if (c->u->u_nfblocks >= CO_MAXBLOCKS) { - PyErr_SetString(PyExc_SystemError, + PyErr_SetString(PyExc_SyntaxError, "too many statically nested blocks"); return 0; }