Skip to content

Commit ee7bc89

Browse files
committed
Update documentation
1 parent 0add3aa commit ee7bc89

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Doc/library/exceptions.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,18 @@ The following exceptions are the exceptions that are usually raised.
436436

437437
The source code text involved in the error.
438438

439+
.. attribute:: end_lineno
440+
441+
Which line number in the file the error occurred ends in. This is
442+
1-indexed: the first line in the file has a ``lineno`` of 1.
443+
444+
.. attribute:: end_offset
445+
446+
The column in the end line where the error occurred finishes. This is
447+
1-indexed: the first character in the line has an ``offset`` of 1.
448+
449+
.. versionchanged:: 3.10
450+
Added the :attr:`end_lineno` and :attr:`end_offset` attributes.
439451

440452
.. exception:: IndentationError
441453

Doc/whatsnew/3.10.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,31 @@ These improvements are inspired by previous work in the PyPy interpreter.
171171
(Contributed by Pablo Galindo in :issue:`42864` and Batuhan Taskaya in
172172
:issue:`40176`.)
173173
174+
:exc:`SyntaxError` exceptions raised by the intepreter will now highlight the
175+
full error range of the expression that consistutes the syntax error itself,
176+
instead of just where the problem is detected. In this way, instead of displaying
177+
(before Python 3.10):
178+
179+
.. code-block:: python
180+
181+
>>> foo(x, z for z in range(10), t, w)
182+
File "<stdin>", line 1
183+
foo(x, z for z in range(10), t, w)
184+
^
185+
SyntaxError: Generator expression must be parenthesized
186+
187+
now Python 3.10 will display the exception as:
188+
189+
.. code-block:: python
190+
191+
>>> foo(x, z for z in range(10), t, w)
192+
File "<stdin>", line 1
193+
foo(x, z for z in range(10), t, w)
194+
^^^^^^^^^^^^^^^^^^^^
195+
SyntaxError: Generator expression must be parenthesized
196+
197+
This improvement has been contributed by Pablo Galindo in :issue:`43914`.
198+
174199
A considerable amount of new specialized messages for :exc:`SyntaxError` exceptions
175200
have been incorporated. Some of the most notable ones:
176201

0 commit comments

Comments
 (0)