mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
[3.12] gh-105390: Correctly raise TokenError instead of SyntaxError for tokenize errors (GH-105399) (#105439)
This commit is contained in:
parent
c607551baf
commit
c84d4d165d
6 changed files with 35 additions and 24 deletions
|
@ -84,13 +84,8 @@ _tokenizer_error(struct tok_state *tok)
|
|||
msg = "invalid token";
|
||||
break;
|
||||
case E_EOF:
|
||||
if (tok->level > 0) {
|
||||
PyErr_Format(PyExc_SyntaxError,
|
||||
"parenthesis '%c' was never closed",
|
||||
tok->parenstack[tok->level-1]);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_SyntaxError, "unexpected EOF while parsing");
|
||||
}
|
||||
PyErr_SetString(PyExc_SyntaxError, "unexpected EOF in multi-line statement");
|
||||
PyErr_SyntaxLocationObject(tok->filename, tok->lineno, tok->inp - tok->buf < 0 ? 0 : tok->inp - tok->buf);
|
||||
return -1;
|
||||
case E_DEDENT:
|
||||
msg = "unindent does not match any outer indentation level";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue