[Zope-dev] PythonScript errormessages in 2.4

Michel Pelletier michel@digicool.com
Wed, 25 Jul 2001 22:41:13 -0700


Chris Withers wrote:
> 
> Hi,
> 
> Is it just me or are the errormessages from parse and syntax errors in
> PythonScripts from Zope 2.4 next to useless?

For a certain definition of useless, yes.

> >   Script line 1
> >     REQUEST = context.REQUEST
> >                              ^
> > SyntaxError: invalid syntax
> 
> This isn't where the error is, 

But it's where python *thinks* the error is.  For a certain class of
syntax errors, python cannot tell you exactly where the error is.  I
have no reason to give you why this is, but Python is not the only
language effected by this, C programmers are often confronted by
compiler errors reported on the next or previous line from the actual
error.  I wouldn't doubt it if other langauges have this problem for
certain classes of errors also.  That's just life.

What's odd is that you said it's an indentation error.  When I try this
script with python 2.1:

  print 'hi'
  for i in range(10):
  print 'foo'

I don't get a SyntaxError, I get an IndentationError:

  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/tmp/python-2029Osa", line 4
      print 'foo'
          ^
  IndentationError: expected an indented block

Notice that it also points to a weird place.

-Michel