[Python-Dev] less quick patch for better debugging.

Guido van Rossum guido at python.org
Thu Nov 27 12:41:29 EST 2003

> >> a[1] + b[2] + c[3]...currently gives an error message that doesnt
> >> say which variable the list index error occurs in or at which
> >> index it occurs at

I would like to point out that one solution suggested here (store the
most recently used name in the object itself) cannot work -- in an
expression like x[i][j], if it is the [j] part that fails, the object
name displayed might be some local variable in an earlier scope that
briefly refenced x[i], and that would be just plain confusing.  This
apart from the significant memory and CPU time overhead (which I
expect whoever requested the feature doesn't care about, until they
have code that runs too slow, and then they will requested a
Python-to-C compiler, and be indignant when they are asked to write it
themselves :-).

> > This would be considerably improved if the error message could
> > just point out the position in the line instead of just the line
> > number.
> Any ideas how to do that?  I guess you could obfuscate c_lnotab even
> more...

Probably not worth it.  (I should mention that I have a possible use
case for messing with the lnotab to contain line numbers in a
different file than the Python source code. :-)

> > Especially when a statement spans more than one line -- currently
> > you can't even tell which line of a multi-line statement was the
> > culprit!
> This is occasionally very annoying, and is probably fixable -- would
> require pretty serious compiler hackery, though.

BTW, for the special case of multi-line argument lists, it is already

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list