Python needs better error reporting

Bengt Richter bokr at oz.net
Sat Jun 29 14:13:52 EDT 2002


On Sat, 29 Jun 2002 07:25:58 -0400, Tim Peters <tim.one at comcast.net> wrote:

>[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.
>
ISTM that's a cute counter-anthropomorphism ;-) I.e., a computer is more than a
passive communication link.

>When we ship Guido with every compiler, the world will be a better place for
>sure.
>
More cuteness ;-)

>> 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 == ' '
>
>include
>
>    '
>    "
>    '''
>    """
>    ==
>    !=
>    <>
>    <
>    <=
>    >
>    >=
>    +
>    -
>    /
>    *
>    **
>and
>    \
>
>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>.
>
What if you had a daemon watching you? It could notice what you did to correct
syntax errors. Then it could say, "Last time you got this kind of syntax
error, you just added a ':' to the end of the line and that took care of it."
I guess you could look at before and after parse structure to figure out the
role of the changed tokens ...

Ok, there's a lot of hand waving in that, but the idea is for it to recognize
actual erroneous patterns of usage and do statistics, as opposed to accounting
for all possible errors and reporting error instances as if all errors were
equally probable.

And then maybe add some AI hype and an animated GUI paper clip in the shape
of a dancing python with a policeman's cap ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list