[Python-ideas] Have REPL print less by default
Steven D'Aprano
steve at pearwood.info
Wed Apr 20 21:58:52 EDT 2016
On Tue, Apr 19, 2016 at 06:28:40PM -0400, Terry Reedy wrote:
> On 4/19/2016 12:18 PM, Steven D'Aprano wrote:
> >I mostly agree with what you say, but I would like to see one change to
> >the default sys.excepthook: large numbers of *identical* traceback lines
> >(as you often get with recursion errors) should be collapsed. For
> >example:
>
> Tracebacks produce *pairs* of lines: the location and the line itself.
Only if the source code is available. The source isn't available for
functions defined in the REPL, for C code, or for Python functions
read from a .pyc file where the .py file is not available.
The code I gave before works with pairs of location + source, without
any change. If I move the definition of fact into a file, so that the
source lines are included, we get:
py> sys.setrecursionlimit(10)
py> fact(30)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/steve/python/fact.py", line 3, in fact
return n*fact(n-1)
[...repeat previous line 7 times...]
File "/home/steve/python/fact.py", line 2, in fact
if n < 1: return 1
RuntimeError: maximum recursion depth exceeded in comparison
I'd want to adjust the wording. Perhaps "previous entry" rather than
previous line?
> Replacing pairs with a count of repetitions would not lose information,
> and would make the info more visible. I would require at least, say, 3
> repetitions before collapsing.
That's what my example does: it only collapses the line/(pair of lines)
if there are at least three identical repetitions.
--
Steve
More information about the Python-ideas
mailing list