Why doesn't Python (error msg) tell me WHAT the actual (arg) values are ?
Peter J. Holzer
hjp-python at hjp.at
Fri Feb 24 14:01:44 EST 2023
On 2023-02-22 15:46:09 -0800, Hen Hanna wrote:
> On Wednesday, February 22, 2023 at 12:05:34 PM UTC-8, Hen Hanna wrote:
> > > py bug.py
> > Traceback (most recent call last):
> > File "C:\Usenet\bug.py", line 5, in <module>
> > print( a + 12 )
> > TypeError: can only concatenate str (not "int") to str
> >
> >
> > Why doesn't Python (error msg) do the obvious thing and tell me
> > WHAT the actual (offending, arg) values are ?
> >
> > In many cases, it'd help to know what string the var A had , when the error occurred.
> > ------------ i wouldn't have to put print(a) just above, to see.
> >
> > ( pypy doesn't do that either, but Python makes programming
> > (debugging) so easy that i hardly feel any inconvenience.)
That seems like a non-sequitur to me. If you hardly feel any
inconvenience, why argue so forcefully?
And why is pypy relevant here?
> i see that my example would be clearER with this one-line change:
>
>
> > py bug.py
>
> Traceback (most recent call last):
>
> File "C:\Usenet\bug.py", line 5, in <module>
> map( Func, fooBar( X, Y, X + Y ))
>
> TypeError: can only concatenate str (not "int") to str
>
>
> i hope that NOW a few of you can see this as a genuine, (reasonable) question.
That doesn't seem a better example to me. There is still only one
subexpression (X + Y) where that error can come from, so I know that X
is a str and Y is an int.
A better example would be something like
x = (a + b) * (c + d)
In this case it could be either (a + b) or (c + d) which caused the
error. But what I really want to know here is the names of the involved
variables, NOT the values. If the error message told me that the values
were 'foo' and 12.3, I still wouldn't be any wiser. The problem here of
course is that the operands aren't necessarily simple variables as in
this example - they may be arbitrarily complex expressions. However, it
might be sufficient to mark the operator which caused the exception:
| ...
| File "/home/hjp/tmp/./foo", line 4, in f
| return (a + b) * (c + d)
| ^
| TypeError: can only concatenate str (not "int") to str
would tell me that (c + d) caused the problem and therefore that c must
be a str which it obviously shouldn't be.
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230224/3b36c3f2/attachment.sig>
More information about the Python-list
mailing list