diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-04-23 13:27:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 13:27:05 (GMT) |
commit | a77aac4fca9723b8fd52a832f3e9df13beb25113 (patch) | |
tree | a504aa9fed91cd31849cdda3ecb1dad439a93778 /Include | |
parent | 91b69b77cf5f78de6d35dea23098df34b6fd9e53 (diff) | |
download | cpython-a77aac4fca9723b8fd52a832f3e9df13beb25113.zip cpython-a77aac4fca9723b8fd52a832f3e9df13beb25113.tar.gz cpython-a77aac4fca9723b8fd52a832f3e9df13beb25113.tar.bz2 |
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way:
>>> foo(x, z for z in range(10), t, w)
File "<stdin>", line 1
foo(x, z for z in range(10), t, w)
^
SyntaxError: Generator expression must be parenthesized
becomes
>>> foo(x, z for z in range(10), t, w)
File "<stdin>", line 1
foo(x, z for z in range(10), t, w)
^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/pyerrors.h | 9 | ||||
-rw-r--r-- | Include/internal/pycore_symtable.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Include/cpython/pyerrors.h b/Include/cpython/pyerrors.h index 9d88e66..5e57129 100644 --- a/Include/cpython/pyerrors.h +++ b/Include/cpython/pyerrors.h @@ -20,6 +20,8 @@ typedef struct { PyObject *filename; PyObject *lineno; PyObject *offset; + PyObject *end_lineno; + PyObject *end_offset; PyObject *text; PyObject *print_file_and_line; } PySyntaxErrorObject; @@ -148,6 +150,13 @@ PyAPI_FUNC(void) PyErr_SyntaxLocationObject( int lineno, int col_offset); +PyAPI_FUNC(void) PyErr_RangedSyntaxLocationObject( + PyObject *filename, + int lineno, + int col_offset, + int end_lineno, + int end_col_offset); + PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject( PyObject *filename, int lineno); diff --git a/Include/internal/pycore_symtable.h b/Include/internal/pycore_symtable.h index 5d34a6c..22f5fcb 100644 --- a/Include/internal/pycore_symtable.h +++ b/Include/internal/pycore_symtable.h @@ -62,6 +62,8 @@ typedef struct _symtable_entry { int ste_comp_iter_expr; /* non-zero if visiting a comprehension range expression */ int ste_lineno; /* first line of block */ int ste_col_offset; /* offset of first line of block */ + int ste_end_lineno; /* end line of block */ + int ste_end_col_offset; /* end offset of first line of block */ int ste_opt_lineno; /* lineno of last exec or import * */ int ste_opt_col_offset; /* offset of last exec or import * */ struct symtable *ste_table; |