[Python-Dev] Misleading syntax error text

M.-A. Lemburg mal@lemburg.com
Mon, 01 Nov 1999 00:00:55 +0100


[Extracted from the psa-members list...]

Gordon McMillan wrote:
> 
> Chris Fama wrote,
> > And now the rub: the exact same function definition has passed
> > through byte-compilation perfectly OK many times before with no
> > problems... of course, this points rather clearly to the
> > preceding code, but it illustrates a failing in Python's syntax
> > error messages, and IMHO a fairly serious one at that, if this is
> > indeed so.
> 
> My simple experiments refuse to compile a "del getattr(..)" at
> all.

Hmm, it seems to be a failry generic error:

>>> del f(x,y)
SyntaxError: can't assign to function call

How about chainging the com_assign_trailer function in Python/compile.c
to:

static void
com_assign_trailer(c, n, assigning)
        struct compiling *c;
        node *n;
        int assigning;
{
        REQ(n, trailer);
        switch (TYPE(CHILD(n, 0))) {
        case LPAR: /* '(' [exprlist] ')' */
                com_error(c, PyExc_SyntaxError,
                          assigning ? "can't assign to function call":
			              "can't delete expression");
                break;
        case DOT: /* '.' NAME */
                com_assign_attr(c, CHILD(n, 1), assigning);
                break;
        case LSQB: /* '[' subscriptlist ']' */
                com_subscriptlist(c, CHILD(n, 1), assigning);
                break;
        default:
                com_error(c, PyExc_SystemError, "unknown trailer type");
        }
}

or something along those lines...

BTW, has anybody tried my import patch recently ? I haven't heard
any citicism since posting it and wonder what made the list fall
asleep over the topic :-)

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    61 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/