File tree 2 files changed +37
-0
lines changed 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -436,6 +436,18 @@ The following exceptions are the exceptions that are usually raised.
436
436
437
437
The source code text involved in the error.
438
438
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.
439
451
440
452
.. exception :: IndentationError
441
453
Original file line number Diff line number Diff line change @@ -171,6 +171,31 @@ These improvements are inspired by previous work in the PyPy interpreter.
171
171
(Contributed by Pablo Galindo in :issue:`42864 ` and Batuhan Taskaya in
172
172
:issue:`40176 ` .)
173
173
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
+
174
199
A considerable amount of new specialized messages for :exc:`SyntaxError ` exceptions
175
200
have been incorporated. Some of the most notable ones:
176
201
You can’t perform that action at this time.
0 commit comments