[Python-Dev] SyntaxError patches

Peter Funk pf@artcom-gmbh.de
Wed, 12 Jul 2000 10:27:01 +0200 (MEST)

> On Tue, 11 Jul 2000, Fred L. Drake, Jr. wrote:
> > At one point, we were discussing having specializations of
> > SyntaxError, and I posted a patch that defined IndentationError and
> > TabError.
Ka-Ping Yee:
> I guess the question is, will we ever want to catch or distinguish
> just IndentationError or TabError exceptions in particular from
> within a Python program?

I don't believe this.

> I can't personally think of any situations where i would need more
> detail than SyntaxError (whatever the error is, i'll just want to
> say "syntax error" and show the message)... unless... should the
> expected token type be passed *all* the way back to the user level
> so that e.g. an IDE can provide a UI hint as to how to correct the
> syntax error?

That sounds rather complicated anyway, but it would certainly be nice for
people using (or should I say needing?) an IDE.

BTW: The following mistake has happened to me to in the past (I'm using
the VI improved editor unter X11):  If cut'n'pasting methods around
between classes, sometimes I unintentionally copy a space character too
much, so that the 'def' of the copied method is intended one blank to
much to the right.  Hmmmm... I should make this clearer using an example:

class Foo(Bar):
     def pasted_method(self, ....)
#---^ note this additional blank here (resulting in a 5 space indent).
	 # ...a screenful of indented code snipped here...
    def another_method(self, baz, bang):
# Python 1.5.2 barfs here with "SyntaxError: invalid token"

This is not very intuitive and hard to see.  The first time I stumbled 
about this it has taken me quite some time to discover my mistake.

I wonder, if the error message could be improved.  That would be
a very valuable improvement for newbies.  However this example might
proove that the idea an IDE would be able to provide UI-hints for 
fixing errors is doomed to fail in the general case.
Regards, Peter.