[issue34683] Caret positioned wrong for SyntaxError reported by ast.c
Guido van Rossum
report at bugs.python.org
Fri Sep 14 13:22:22 EDT 2018
New submission from Guido van Rossum <guido at python.org>:
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 <report at bugs.python.org>
<https://bugs.python.org/issue34683>
_______________________________________
More information about the Python-bugs-list
mailing list