bpo-43555: Report the column offset for invalid line continuation character (GH-24939)

This commit is contained in:
Pablo Galindo 2021-03-22 17:28:11 +00:00 committed by GitHub
parent 123ff266cd
commit 96eeff5162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 6 deletions

View file

@ -328,6 +328,7 @@ tokenizer_error(Parser *p)
const char *msg = NULL;
PyObject* errtype = PyExc_SyntaxError;
Py_ssize_t col_offset = -1;
switch (p->tok->done) {
case E_TOKEN:
msg = "invalid token";
@ -359,16 +360,14 @@ tokenizer_error(Parser *p)
msg = "too many levels of indentation";
break;
case E_LINECONT:
col_offset = strlen(strtok(p->tok->buf, "\n")) - 1;
msg = "unexpected character after line continuation character";
break;
default:
msg = "unknown parsing error";
}
PyErr_Format(errtype, msg);
// There is no reliable column information for this error
PyErr_SyntaxLocationObject(p->tok->filename, p->tok->lineno, 0);
RAISE_ERROR_KNOWN_LOCATION(p, errtype, p->tok->lineno, col_offset, msg);
return -1;
}