gh-126139: Improve error message location for future statement with unknown feature (#126140)

This commit is contained in:
Brian Schubert 2024-10-29 19:57:59 -04:00 committed by GitHub
parent 9dfef4e5f4
commit 224c370a36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 8 deletions

View file

@ -41,12 +41,20 @@ future_check_features(_PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
} else if (strcmp(feature, "braces") == 0) {
PyErr_SetString(PyExc_SyntaxError,
"not a chance");
PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset + 1);
PyErr_RangedSyntaxLocationObject(filename,
name->lineno,
name->col_offset + 1,
name->end_lineno,
name->end_col_offset + 1);
return 0;
} else {
PyErr_Format(PyExc_SyntaxError,
UNDEFINED_FUTURE_FEATURE, feature);
PyErr_SyntaxLocationObject(filename, s->lineno, s->col_offset + 1);
PyErr_RangedSyntaxLocationObject(filename,
name->lineno,
name->col_offset + 1,
name->end_lineno,
name->end_col_offset + 1);
return 0;
}
}