classification
Title: Highlight invalid ranges in SyntaxErrors
Type: Stage: patch review
Components: Parser Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: aroberge, eric.araujo, lys.nikolaou, pablogsal, terry.reedy
Priority: normal Keywords: patch

Created on 2021-04-22 18:08 by pablogsal, last changed 2021-04-25 11:06 by aroberge.

Pull Requests
URL Status Linked Edit
PR 25525 merged pablogsal, 2021-04-22 18:08
PR 25582 open terry.reedy, 2021-04-24 22:35
Messages (4)
msg391620 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-22 18:08
To improve the user experience understanding what part of the error messages associated to SyntaxErrors are 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
msg391697 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-23 13:27
New changeset a77aac4fca9723b8fd52a832f3e9df13beb25113 by Pablo Galindo in branch 'master':
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
https://github.com/python/cpython/commit/a77aac4fca9723b8fd52a832f3e9df13beb25113
msg391729 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2021-04-23 19:32
What a great, useful change!
msg391808 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-04-24 21:46
Great!!!  I also tried
>>> try: compile("a xyzjdkjfk", '', 'single')
except SyntaxError as e:
	print(e, e.msg, e.lineno, e.offset, e.end_lineno, e.end_offset)

	
invalid syntax. Perhaps you forgot a comma? (, line 1) invalid syntax. Perhaps you forgot a comma? 1 1 1 12

The language change that enables the display change is the addition of end_lineno and end_offset attributes.  I will look into using these in IDLE.  I will submit a PR to augment the What's New entry, so others can  also improve their error marking.
History
Date User Action Args
2021-04-25 11:06:50arobergesetnosy: + aroberge
2021-04-24 22:35:49terry.reedysetstage: patch review
pull_requests: + pull_request24302
2021-04-24 21:46:00terry.reedysetnosy: + terry.reedy
messages: + msg391808
2021-04-23 19:32:02eric.araujosetnosy: + eric.araujo
messages: + msg391729
2021-04-23 13:27:25pablogsalsetmessages: + msg391697
2021-04-22 18:13:31pablogsalsetcomponents: + Parser
2021-04-22 18:10:30pablogsalsetnosy: + lys.nikolaou

stage: patch review -> (no value)
2021-04-22 18:08:24pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request24245
2021-04-22 18:08:13pablogsalsetversions: + Python 3.10
2021-04-22 18:08:10pablogsalcreate