diff options
author | Marta Gómez Macías <mgmacias@google.com> | 2023-05-22 11:30:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-22 11:30:18 (GMT) |
commit | 729b252241966f464cc46e176fb854dbcc5296cb (patch) | |
tree | 504b8a8c45364d456124dcbe79140bd0a5b7c2ad /Python | |
parent | 0a7796052acb9cec8b13f8d0a5f304f56f26ec5b (diff) | |
download | cpython-729b252241966f464cc46e176fb854dbcc5296cb.zip cpython-729b252241966f464cc46e176fb854dbcc5296cb.tar.gz cpython-729b252241966f464cc46e176fb854dbcc5296cb.tar.bz2 |
gh-104741: Add line number attribute to indentation error exception (#104743)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-tokenize.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Python/Python-tokenize.c b/Python/Python-tokenize.c index 43b44be..f7e32d3 100644 --- a/Python/Python-tokenize.c +++ b/Python/Python-tokenize.c @@ -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; |