[Python-ideas] Shrink recursion error tracebacks (was: Have REPL print less by default)

Terry Reedy tjreedy at udel.edu
Fri Apr 22 23:15:15 EDT 2016

On 4/22/2016 10:00 PM, Émanuel Barry wrote:
> I have been thinking, and especially after Nick’s comments, that it
> might be better to keep it as simple as possible to reduce the risk of
> errors happening while we’re printing the tracebacks. Recursive
> functions (that go deep enough to trigger an exception) are usually
> within one function, in the REPL, or by using __getattr__ /
> __getattribute__. Nice to have? Sure. Necessary? Don’t think as much.

I agree (I think) that the first issue and patch should be to detect and 
collapse n identical lines or pairs of lines in a row, where n > 3, with 
a message "The above pair of lines [or line] is repeated n-1 more times."
This will be an optional but nice new feature giving 80% benefit for 20% 
work.  There seems to be a consensus for this much.  Lets do it.

> I’m also a very solid -1 on the idea of prompting the user to do
> something like full_ex() to get the full stack trace. My rationale for
> such a change is that we need to be extremely precise in our message, to
> leave absolutely no room for a different interpretation than what we
> mean. Your message, for instance, is ambiguous. The fact it says that
> calls are hidden would let me think I just lost information about the
> stack trace (though that’s but a wording issue). As a user, just seeing
> "Call _full_ex() to print full trace." would be an immediate red flag:
> Crap, I just lost precious debugging information to save on lines!
> Might be just me, but that’s my opinion anyway :)

I agree that anything beyond the first step is more dubious.  I think 
extensions should be another proposal and possible issue.  Or left to 
GUI wrappers of an underlying Python.

> Example:
>     File "<stdin>", line 1, in f
>     File "<stdin>", line 1, in g
>     [Mutually recursive calls hidden: f (300), g (360)]
>     File "<stdin>", line 1, in h
>     File "<stdin>", line 1, in f
>     File "<stdin>", line 1, in g
>    [Mutual-recursive calls hidden: f (103), g (200)]
>   RuntimeError: maximum recursion depth exceeded
>   [963 calls hidden. Call _full_ex() to print full trace.]
> This rule is easily modified to, "have been seen at least three times
> before." For functions that recurse at multiple lines, it can print out
> one message per line, but maybe it should count them all together in the
> "hidden" summary.

Terry Jan Reedy

More information about the Python-ideas mailing list