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 /Doc/whatsnew | |
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 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.10.rst | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 67e03f2..86cf11f 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -171,6 +171,31 @@ These improvements are inspired by previous work in the PyPy interpreter. (Contributed by Pablo Galindo in :issue:`42864` and Batuhan Taskaya in :issue:`40176`.) +:exc:`SyntaxError` exceptions raised by the intepreter will now highlight the +full error range of the expression that consistutes the syntax error itself, +instead of just where the problem is detected. In this way, instead of displaying +(before Python 3.10): + +.. code-block:: python + + >>> 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 + +now Python 3.10 will display the exception as: + +.. code-block:: python + + >>> 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 + +This improvement has been contributed by Pablo Galindo in :issue:`43914`. + A considerable amount of new specialized messages for :exc:`SyntaxError` exceptions have been incorporated. Some of the most notable ones: |