]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
authorPablo Galindo <Pablogsal@gmail.com>
Fri, 23 Apr 2021 13:27:05 +0000 (14:27 +0100)
committerGitHub <noreply@github.com>
Fri, 23 Apr 2021 13:27:05 +0000 (14:27 +0100)
commita77aac4fca9723b8fd52a832f3e9df13beb25113
treea504aa9fed91cd31849cdda3ecb1dad439a93778
parent91b69b77cf5f78de6d35dea23098df34b6fd9e53
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
17 files changed:
Doc/library/exceptions.rst
Doc/whatsnew/3.10.rst
Grammar/python.gram
Include/cpython/pyerrors.h
Include/internal/pycore_symtable.h
Lib/test/test_cmd_line_script.py
Lib/test/test_exceptions.py
Lib/test/test_syntax.py
Misc/NEWS.d/next/Core and Builtins/2021-04-22-19-09-58.bpo-43914.0Ik1AM.rst [new file with mode: 0644]
Objects/exceptions.c
Parser/parser.c
Parser/pegen.c
Parser/pegen.h
Python/compile.c
Python/errors.c
Python/pythonrun.c
Python/symtable.c