Python needs better error reporting

Hans-Joachim Widmaier hjwidmaier at web.de
Tue Jul 2 07:05:16 EDT 2002


"James J. Besemer" <jb at cascade-sys.com> wrote in message news:<mailman.1025421223.12379.python-list at python.org>...

> Tim Peters wrote:
> 
> > Well, "xor" isn't legit there, but other tokens that are OK after
> >
> >     if s == ' '
> >
> > include
> >
> >    [a ong list]
> 
> The question is NOT be what all may follow the string literal.  Rather it should
> be what tokens are legal between the string literal and end of line?  Very
> different questions.
> 
> If I'm not mistaken, only ":" or "\" are legal in that narrow context.

Instead of listing all the legitimate tokens that may follow, why not
just give something like "Incomplete 'if' statement?"

This "invalid syntax" is really kind of a lazy excuse (there's this
one operating system that gives errors like "Error: one of the
bazillion operations you started by clicking on that button did not
work." Helps a lot. Really.)

The other day I removed a try/except and forgot to dedent the block.
"SyntaxError: invalid syntax" Embarrassing as it is, but it took me a
while to figure out what was wrong. "Unexpected indent" or "Unexpected
start of block" or something along those lines would have showed me
directly what the error was.

Whenever I write a parser, I try really hard to tell the user why an
error is thrown (and surely fail miserably). Python, being such a
beginner-friendly language, ought to do better than "invalid syntax."

Guess I just shouldn't make errors any more. ;-)

Hans-Joachim



More information about the Python-list mailing list