[Python-ideas] Function arguments in tracebacks
Nick Coghlan
ncoghlan at gmail.com
Fri Dec 30 10:28:47 EST 2016
On 29 December 2016 at 08:13, Nathaniel Smith <njs at pobox.com> wrote:
> On Dec 28, 2016 12:44, "Brett Cannon" <brett at python.org> wrote:
>
> My quick on-vacation response is that attaching more objects to exceptions
> is typically viewed as dangerous as it can lead to those objects being kept
> alive longer than expected (see the discussions about richer error messages
> to see that worry come out for something as simple as attaching the type to
> a TypeError).
>
>
> This isn't an issue for printing arguments or other locals in tracebacks,
> though. The traceback printing code can access anything in the frame stack.
>
Right, the reasons for the discrepancy here are purely pragmatic ones:
- the default traceback printing machinery in CPython is written in C, and
we don't currently have readily available tools at that layer to print a
nice structured argument list the way gdb does for C functions (and there
are good reasons for us to want the interpreter to be able to print
tracebacks even if it's in a sufficiently unhealthy state that the
"traceback" module won't run, so delegating the problem to Python level
tooling isn't an answer for CPython)
- displaying local variables in runtime tracebacks (as opposed to in
interactive debuggers like gdb) is a known security risk that we don't
currently provide good tools for handling in the standard library (e.g. we
don't offer str and bytes subclasses with opaque representations that don't
reveal their contents). Even if we did offer them, they'd still be opt-in
for reasons of usability when working with data that *isn't* security
sensitive.
However, neither of those arguments applies to the "where" command in pdb,
and that doesn't currently display this kind of information either:
>>> def f(x, y, message):
... return x/y, message
...
>>> f(2, 0, "Hello world")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
ZeroDivisionError: division by zero
>>> import pdb; pdb.pm()
> <stdin>(2)f()
(Pdb) w
<stdin>(1)<module>()->None
> <stdin>(2)f()
(Pdb)
pdb already knows what the arguments are, as it can print them if you ask
for them explicitly:
(Pdb) args
x = 2
y = 0
message = 'Hello world'
So I think this kind of change may make a lot of sense as an RFE for pdb's
"where" command (with the added bonus that projects like pdbpp could make
it available to earlier Python versions as well).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161231/bf7ecc0a/attachment.html>
More information about the Python-ideas
mailing list