Re: how to discover what values produced an exception?
On Tue, 7 May 2024 at 03:38, Alan Bawden via Python-list wrote: > A good error message shouldn't withhold any information that can > _easily_ be included. Debugging is more art than science, so there is > no real way to predict what information might prove useful in solving > the crime. I emphasized "easily" because of course you have to draw the > line somewhere. Emphasis on "easily" is correct here. How easy is it to report the value of something that could be arbitrarily large? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
From a practical perspective: not all values are printable (especially if printing a value results in an error: then you'd lose the original error, so, going crazy with printing of errors is usually not such a hot idea). But, if you want the values: you'd have to examine the stack, extract the values from the local variables etc. It's easier to do this interactively (unless you are in a multithreaded environment, where pdb is broken). But, you could also try to find this information automatically (by unwinding the stack to the place that generated the error, examining the local variables etc.) It's tedious and prone to errors. So, if you really want to do this automatically for every error that's going to be quite a bit of work. On Fri, May 3, 2024 at 6:58 PM Johanne Fairchild via Python-list 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 "", line 1, in > 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. > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
Thomas Passin writes: On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list 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 "", line 1, in > 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. In this example it would not help at all to know the actual values. Knowing that you are trying to compare incomparable types is enough. In general, it absolutely can help. The programmer can sometimes recognize where a value of unexpected type came from just by looking at it, allowing her to quickly deduce just what went wrong without further investigation. A good error message shouldn't withhold any information that can _easily_ be included. Debugging is more art than science, so there is no real way to predict what information might prove useful in solving the crime. I emphasized "easily" because of course you have to draw the line somewhere. The fact that Python error messages often fail to mention the actual objects that caused the error has always annoyed me. I've always presumed that for some reason it just wasn't easy to do. And it's never been more than a minor annoyance to me. So the OP is not wrong for wishing for this. Other programming languages do it. Other Python programmers miss it. - Alan -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
On 2024-05-03 at 10:56:39 -0300, Johanne Fairchild via Python-list 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 "", line 1, in > 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
Re: how to discover what values produced an exception?
Johanne Fairchild wrote at 2024-5-3 10:56 -0300: >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 "", line 1, in >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. Typically, the traceback informs you about the source code line where the exception has been raised. When the source line contains literals, you see the values. If not, then only in special (speak: rather simple) cases the knowledge of the values will help much. Usually, a more thorough analysis is required to find out the bug location and how to fix the bug. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list 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 "", line 1, in 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. In this example it would not help at all to know the actual values. Knowing that you are trying to compare incomparable types is enough. -- https://mail.python.org/mailman/listinfo/python-list
how to discover what values produced an exception?
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 "", line 1, in 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. -- https://mail.python.org/mailman/listinfo/python-list