On 2024-05-03 at 10:56:39 -0300,
Johanne Fairchild via Python-list <python-list@python.org> wrote:

> How to discover what values produced an exception?  Or perhaps---why
> doesn't the Python traceback show the values involved in the TypeError?
> For instance:
> 
> --8<-------------------------------------------------------->8---
> >>> (0,0) < 4
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: '<' not supported between instances of 'tuple' and 'int'
> --8<-------------------------------------------------------->8---
> 
> It could have said something like: 
> 
> --8<-------------------------------------------------------->8---
> TypeError: '<' not supported between instances of 'tuple' and 'int'
>   in (0,0) < 4.
> --8<-------------------------------------------------------->8---
> 
> We would know which were the values that caused the problem, which would
> be very helpful.

I'm not disagreeing that knowing the values could be useful in many
cases.  In the general case, though, it's not practical.  Consider a
function like this:

    def f(x, y):
        return g(x) < h(y)

The printed values of x, y, g(x), and h(y) could all be millions of (or
more) glyphs.  Worse, one or more of those values could contain circular
lists or similar structures.  And h or g could have changed x or y.  In
summary, printing run-time values isn't always safe or useful.  At least
printing the types is safe.  In the face of ambiguity, refuse to guess.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to