Message188133
| Author |
ezio.melotti |
| Recipients |
ezio.melotti, flox, georg.brandl, giampaolo.rodola, icordasc, lesmana, ncoghlan, petri.lehtinen, psss, terry.reedy |
| Date |
2013年04月30日.07:12:21 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1367305942.02.0.480726829877.issue12458@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I think all the lines involved in a multi-line expression should be reported.
Take for example this simple code:
x = [int(c, 16)
for c in '0123456789ABCDEFG'
if c.isdigit() or c.isupper()]
With Python 2 the traceback is:
Traceback (most recent call last):
File "deleteme.py", line 3, in <module>
if c.isdigit() or c.isupper()]
ValueError: invalid literal for int() with base 16: 'G'
Which is not very helpful, because you don't see the int() call that is causing the error in the first place and you don't see where the G comes from.
Incidentally, for this specific case, the traceback is a bit better on Python3:
Traceback (most recent call last):
File "deleteme.py", line 2, in <module>
for c in '0123456789ABGDEF'
File "deleteme.py", line 3, in <listcomp>
if c.isdigit() or c.isupper()]
ValueError: invalid literal for int() with base 16: 'G'
But this still misses the int() call.
IMHO it would be better to have something like:
Traceback (most recent call last):
File "deleteme.py", lines 1-3, in <module>
x = [int(c, 16)
for c in '0123456789ABCDEFG'
if c.isdigit() or c.isupper()]
ValueError: invalid literal for int() with base 16: 'G'
If this is rejected for some reason, I think printing the first line -- rather than the last -- would still be an improvement, because in most of the cases the first line contains more information (e.g. the name of the function with a multi-line list of args, a raise/assert with the name of the exception and part of the message, the operation done for each element of a genexp/listcomp). |
|