[Edu-sig] Python error messages

Greg Ward gward@cnri.reston.va.us
Tue, 15 Feb 2000 09:40:35 -0500

On 15 February 2000, Guido van Rossum said:
> Others too -- if you see a poorly worded or otherwise undecipherable
> (for a beginner) error coming from Python, let me know!

At the risk of contributing to another geek-oriented thread (as opposed
to educator-oriented), let me just say that my least-favourite Python
error message is "SyntaxError: invalid syntax", which somehow manages to
be both overly terse and redundant at the same time.

As long as I'm picking nits without making any constructive
contribution, how about:

>>> 4 + "foo"
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: number coercion failed

...wouldn't it be nicer to say "can't add string and number"?  (I'm
coming at this from a usability perspective, not from an implementation
perspective -- which means I'm allowed to make unrealistic requests!)

And when I reverse the arguments, I get a somewhat more useful message:

>>> "foo" + 4
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: illegal argument type for built-in operation

...but it would be nice to know *which* built-in operation is causing
the problem, e.g. "illegal argument type for addition operation".  Come
to think of it, shouldn't that be "illegal argument types"?  After all,
both string and integer are legal argument types for addition -- it's
just the combination that's illegal.

It might be a useful exercise for someone to hang onto "first pass"
Python programs written by novices to see what kind of errors happen
most frequently, which error messages are most confusing, and work on