gh-104741: Add line number attribute to indentation error exception (#104743)

This commit is contained in:
Marta Gómez Macías 2023-05-22 13:30:18 +02:00 committed by GitHub
parent 0a7796052a
commit 729b252241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -89,11 +89,9 @@ _tokenizer_error(struct tok_state *tok)
}
return -1;
case E_DEDENT:
PyErr_Format(PyExc_IndentationError,
"unindent does not match any outer indentation level "
"(<tokenize>, line %d)",
tok->lineno);
return -1;
msg = "unindent does not match any outer indentation level";
errtype = PyExc_IndentationError;
break;
case E_INTR:
if (!PyErr_Occurred()) {
PyErr_SetNone(PyExc_KeyboardInterrupt);
@ -131,7 +129,12 @@ _tokenizer_error(struct tok_state *tok)
goto exit;
}
tmp = Py_BuildValue("(OnnOii)", tok->filename, tok->lineno, 0, error_line, 0, 0);
Py_ssize_t offset = _PyPegen_byte_offset_to_character_offset(error_line, tok->inp - tok->buf);
if (offset == -1) {
result = -1;
goto exit;
}
tmp = Py_BuildValue("(OnnOOO)", tok->filename, tok->lineno, offset, error_line, Py_None, Py_None);
if (!tmp) {
result = -1;
goto exit;