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.

Author alexis.d
Recipients alexis.d, benjamin.peterson, christian.heimes, jcea, lemburg
Date 2012-11-22.09:26:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I don't think it can be "fixed" with sys.setrecursionlimit for a few reasons:

* I think the issue arises when the AST is built. Otherwise if we put code before the if it would execute. But that's not the case (try putting a print('hello') before the if and it won't print anything).
  - This also means that you cannot directly call sys.setrecursionlimit in the file with the elifs.
  - Though we can set recursion limit using a second file which will then import the elifs file: I tried with different limits and CPython still crash in the same way (and always with the same number of elifs, roughly, because I didn't binary search for the exact amount of elifs).
  - sys.setrecursionlimit controls the stack size of the running Python program, while here we break C stack directly before running Python bytecode.
* When recursion limit is hit, an exception is raised, there's no segfault:
>>> def f():
...     f()
>>> f()
# plenty of omitted lines
RuntimeError: maximum recursion depth exceeded
* Having a RuntimeError raised would be nice, though 'maximum recursion depth exceeded' may not be the best possible error message as from a 'Python user' POV there's no recursion here.


A possible solution would be, I guess, to store elifs as excepts are stored. Instead of storing elifs recursively, the else part would just contain a list of if nodes (and if there is a else, well just store an if True node).

Though I don't know how difficult it would be to implement that, or if it's likely to break a lot of things which relies on ifs/elifs to be stored that way.
Date User Action Args
2012-11-22 09:26:29alexis.dsetrecipients: + alexis.d, lemburg, jcea, christian.heimes, benjamin.peterson
2012-11-22 09:26:29alexis.dsetmessageid: <>
2012-11-22 09:26:29alexis.dlinkissue16527 messages
2012-11-22 09:26:29alexis.dcreate