Python needs better error reporting

Tim Peters at
Sat Jun 29 07:25:58 EDT 2002

[David LeBlanc]
> Cute anthropomorphism is lots of fun, but doesn't _quite_ obscure the fact
> that computers don't really "tell" anybody anything, programmers do.

When we ship Guido with every compiler, the world will be a better place for

> IIRC, Python throws this "Syntax Error: invalid syntax" in a number of
> places.

Yes.  Study the code a little and you'll soon discover why.

> In the place that I used as an example, looking at the language
> reference, an appropriate error would be more like:
> 	Syntax Error: expected "and", "or", "xor" or ":"

Well, "xor" isn't legit there, but other tokens that are OK after

    if s == ' '



Call me prophetic, but you wouldn't be happy with a list of all
possibilities either.  Collapse oodles of them into "binary operator" and
you lose half the people you're trying to help.  Etc.

> This would at least narrow down what should be looked at to resolve the
> problem.

Not really.  Such lists tend to baffle more than clarify.  I once used a
Pascal compiler whose favorite trick was to point a caret at a trailing
semicolon, and then complain "semicolon expected"; the message was always
correct when it appeared, while appearing dead wrong, and was useless in
determining the *real* problem regardless.  It did appear friendlier than
"syntax error" the first 719 times I saw it, though <wink>.

> Vague error reporting doesn't help new user's self confidance or
> acceptance of the language.
> I really DO have a point!

Error-reporting in parsers has been the subject of intense research.  Do a
little digging and come back when you can make a case that your point can be
addressed effectively.  Keep in mind that most consumer-grade computers
still don't have telepathy chips <wink>.

More information about the Python-list mailing list