mirror of
https://github.com/python/cpython.git
synced 2025-08-22 01:35:16 +00:00
bpo-40985: Show correct SyntaxError text when last line has a LINECONT (GH-20888)
When a file ends with a line that contains a line continuation character the text of the emitted SyntaxError is empty, contrary to the old parser, where the error text contained the text of the last line.
This commit is contained in:
parent
8666356280
commit
113e2b0a07
3 changed files with 13 additions and 4 deletions
|
@ -1646,16 +1646,18 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno)
|
|||
{
|
||||
int i;
|
||||
char linebuf[1000];
|
||||
|
||||
if (fp == NULL)
|
||||
if (fp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < lineno; i++) {
|
||||
char *pLastChar = &linebuf[sizeof(linebuf) - 2];
|
||||
do {
|
||||
*pLastChar = '\0';
|
||||
if (Py_UniversalNewlineFgets(linebuf, sizeof linebuf,
|
||||
fp, NULL) == NULL)
|
||||
break;
|
||||
fp, NULL) == NULL) {
|
||||
goto after_loop;
|
||||
}
|
||||
/* fgets read *something*; if it didn't get as
|
||||
far as pLastChar, it must have found a newline
|
||||
or hit the end of the file; if pLastChar is \n,
|
||||
|
@ -1663,6 +1665,8 @@ err_programtext(PyThreadState *tstate, FILE *fp, int lineno)
|
|||
yet seen a newline, so must continue */
|
||||
} while (*pLastChar != '\0' && *pLastChar != '\n');
|
||||
}
|
||||
|
||||
after_loop:
|
||||
fclose(fp);
|
||||
if (i == lineno) {
|
||||
PyObject *res;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue