gh-104169: Ensure the tokenizer doesn't overwrite previous errors (#104170)

This commit is contained in:
Pablo Galindo Salgado 2023-05-04 15:15:26 +01:00 committed by GitHub
parent e2ef5015d1
commit eba64d2afb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -1277,6 +1277,12 @@ _syntaxerror_range(struct tok_state *tok, const char *format,
int col_offset, int end_col_offset,
va_list vargs)
{
// In release builds, we don't want to overwrite a previous error, but in debug builds we
// want to fail if we are not doing it so we can fix it.
assert(tok->done != E_ERROR);
if (tok->done == E_ERROR) {
return ERRORTOKEN;
}
PyObject *errmsg, *errtext, *args;
errmsg = PyUnicode_FromFormatV(format, vargs);
if (!errmsg) {