[Python-ideas] Have REPL print less by default
Random832
random832 at fastmail.com
Wed Apr 20 15:01:48 EDT 2016
On Wed, Apr 20, 2016, at 14:25, Franklin? Lee wrote:
> 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.]
>
> Or maybe the second f and g are also folded into the second hidden
> bit. And maybe it checks line numbers when deciding whether to print
> explicitly (but not when folding).
>
> Would that output make indirect infinite recursion more difficult for
> you to debug?
You know what would make complicated infinite recursion easier to debug?
The arguments.
Is there a reliable way to determine what in f_locals correspond to
arguments? My toy example below only works for named positional
arguments.
def magic(frame):
code = frame.f_code
fname = code.co_name
argcount = code.co_argcount
args = code.co_varnames[:argcount]
values = tuple(frame.f_locals[a] for a in args)
result = '%s%r' % (fname, values)
if len(result) > 64:
return fname + '(...)'
return result
Maybe even tokenize the source line the error occurred on and print any
other locals whose name matches any token on the line. I guess I'll
leave it to the bikeshed design committee and say: WIBNI tracebacks
printed relevant frame variables FSDO relevant?
More information about the Python-ideas
mailing list