This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients gvanrossum
Date 2018-09-14.17:22:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536945742.16.0.956365154283.issue34683@psf.upfronthosting.co.za>
In-reply-to
Content
Input file with a subtle error: a number where an assignment target is required:

for 1 in []: pass

Run it, it gives a SyntaxError.  Note how the caret pointing to the incorrect token is position one to the left of where you'd expect it:

  File "s.py", line 1
    for 1 in []: pass
       ^
SyntaxError: can't assign to literal

For every syntax error I've seen that's produced by ast.c this seems to be the case -- the caret is always positioned 1 too far left.

I tried to understand how this is happening but my AST-fu is lacking. It seems this has been happening since ast.c started added column numbers -- in Python 2.7 there's no caret at all, but in 3.4 and later there's a caret and it has the same problem. (Also in 3.3; I don't have 3.2 or older 3.x lying around to test.)
History
Date User Action Args
2018-09-14 17:22:22gvanrossumsetrecipients: + gvanrossum
2018-09-14 17:22:22gvanrossumsetmessageid: <1536945742.16.0.956365154283.issue34683@psf.upfronthosting.co.za>
2018-09-14 17:22:22gvanrossumlinkissue34683 messages
2018-09-14 17:22:22gvanrossumcreate