[Python-Dev] Odd compile errors for bad genexps

Raymond Hettinger python at rcn.com
Wed Sep 29 23:30:52 CEST 2004

> >>> (i for i in x) = 2
> SystemError: assign to generator expression not possible
> 1. Why is that a SystemError instead of a SyntaxError?  SystemError
>    doesn't make sense.

It, of course, should be a SyntaxError.
The fix is easy.  Put in PyExc_SyntaxError on line 3206 in compile.c

> 2. Why didn't it echo the offending line?

I don't follow this part.  The output is no different from:

    >>> str(x) = 2
    SyntaxError: can't assign to function call

> >>> (i for i in x) += 2
> SyntaxError: augmented assign to tuple literal not possible
> 3. That's not a tuple literal.

The code for that one was modeled after broken code for list comps:

    >>> [i for i in x] += 2
    SyntaxError: augmented assign to list literal not possible

That's not a list literal either.

For both genexps and listcomps, the test for augmented assignment should
likely be moved before the same test for tuple literals and list
literals (they only check for LPAR or LSQB to trigger their message).

Is there a compiler weenie in the house who knows how to reliably fix
this one?  Though I can see the problem clearly enough, I'm just enough
out of my element that I don't want to touch it.


More information about the Python-Dev mailing list