[issue34683] Caret positioned wrong for SyntaxError reported by ast.c

Benjamin Peterson report at bugs.python.org
Fri Sep 14 14:21:05 EDT 2018


Benjamin Peterson <benjamin at python.org> added the comment:

I think ast.c is in the right here and there are two complementary bugs in caret printing and the parser.

print_error_text does this:

    while (--offset > 0)
        PyFile_WriteString(" ", f);

which is off-by-one if offset is zero-indexed (which it should be IMO).

The parser has an off-by-one error in the other direction. When it reports an error, it reports the offset of the tokenizer's "cur" buffer. This is generally advanced past the location that actually resulted in a parser error. I believe the parser should be fixed to report the error offset as the offset of the start of the token that caused the error.

----------
nosy: +benjamin.peterson -eric.smith, xtreak

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34683>
_______________________________________


More information about the Python-bugs-list mailing list