This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SystemError when compiling deeply nested for loops
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ammar2, benjamin.peterson, brett.cannon, georg.brandl, ncoghlan, ppperry, python-dev, serhiy.storchaka, yselivanov
Priority: normal Keywords: patch

Created on 2016-07-14 12:33 by ppperry, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
nested_blocks.diff ammar2, 2016-07-14 21:24 review
nested_blocks.diff2 ammar2, 2016-07-14 21:37 review
Messages (7)
msg270405 - (view) Author: (ppperry) Date: 2016-07-14 12:33
The following code:
for a in range(26):
  for b in range(26):
   for c in range(26):
    for d in range(26):
     for e in range(26):
      for f in range(26):
       for g in range(26):
        for h in range(26):
         for i in range(26):
          for j in range(26):
           for k in range(26):
            for l in range(26):
             for m in range(26):
              for o in range(26):
               for p in range(26):
                for q in range(26):
                 for r in range(26):
                  for s in range(26):
                   for t in range(26):
                    for u in range(26):
                     for v in range(26):
                       for w in range(26):
                         pass
fails to compile with `SystemError:too many statically nested blocks`, which was described as a serious bug in issue27081.
msg270409 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-07-14 13:41
There is a static limit for the number of statically nested blocks. Getting rid of this limit looks not easy.

But SystemError is not an exception that should be raised. SystemError is for errors that can't be occurred in normal case. It should only be caused by incorrect use of C API or hacking Python internals. I think SyntaxError is more appropriate in this case (as in case of passing more than 255 arguments to a function).
msg270410 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2016-07-14 14:09
+1 for Serhiy's recommendation. It's OK for the compiler to say "Don't do that", but the correct error is SyntaxError, even when it's a limitation later in the code generation pipeline (rather than failing to comply with the language grammar)
msg270445 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2016-07-14 21:24
This patch changes it to a SyntaxError instead of a SystemError.
msg270446 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2016-07-14 21:37
Amended patch with the comment fixed to refer to just the issue numbers according to advice from bitdancer.
msg270462 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-07-15 03:22
LGTM.
msg270464 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-07-15 05:02
New changeset e6e7c8368c70 by Benjamin Peterson in branch '3.5':
make too many nested blocks be a SyntaxError instead of a SystemError (closes #27514)
https://hg.python.org/cpython/rev/e6e7c8368c70

New changeset 345ec7455b75 by Benjamin Peterson in branch '2.7':
make too many nested blocks be a SyntaxError instead of a SystemError (closes #27514)
https://hg.python.org/cpython/rev/345ec7455b75

New changeset d1da87d8b29c by Benjamin Peterson in branch 'default':
merge 3.5 (#27514)
https://hg.python.org/cpython/rev/d1da87d8b29c
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71701
2016-07-15 05:02:21python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg270464

resolution: fixed
stage: commit review -> resolved
2016-07-15 03:22:26serhiy.storchakasetmessages: + msg270462
stage: needs patch -> commit review
2016-07-14 21:37:19ammar2setfiles: + nested_blocks.diff2

messages: + msg270446
2016-07-14 21:24:07ammar2setfiles: + nested_blocks.diff

nosy: + ammar2
messages: + msg270445

keywords: + patch
2016-07-14 14:09:03ncoghlansetmessages: + msg270410
2016-07-14 13:41:11serhiy.storchakasetstage: needs patch
messages: + msg270409
versions: + Python 3.5, Python 3.6
2016-07-14 12:33:51ppperrycreate