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
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index dc81964..0a910bc 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -1212,7 +1212,7 @@ def test_expression_with_assignment(self):
self._check_error(
"print(end1 + end2 = ' ')",
'expression cannot contain assignment, perhaps you meant "=="?',
- offset=19
+ offset=7
)
def test_curly_brace_after_primary_raises_immediately(self):