New submission from Guido van Rossum <[email protected]>:
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.)
----------
messages: 325366
nosy: gvanrossum
priority: low
severity: normal
status: open
title: Caret positioned wrong for SyntaxError reported by ast.c
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34683>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com