File tree 5 files changed +383
-269
lines changed
Misc/NEWS.d/next/Core and Builtins
5 files changed +383
-269
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,20 @@ have been incorporated. Some of the most notable ones:
274
274
275
275
(Contributed by Pablo Galindo in :issue:`43823 ` )
276
276
277
+ * `` try `` blocks without `` except `` or `` finally `` blocks:
278
+
279
+ .. code- block:: python
280
+
281
+ >> > try
282
+ ... x = 2
283
+ ... something = 3
284
+ File " <stdin>" , line 3
285
+ something = 3
286
+ ^^^^^^^^^
287
+ SyntaxError : expected ' except' or ' finally' block
288
+
289
+ (Contributed by Pablo Galindo in :issue:`44305 ` )
290
+
277
291
* Usage of `` =`` instead of `` == `` in comparisons:
278
292
279
293
.. code- block:: python
Original file line number Diff line number Diff line change @@ -964,6 +964,7 @@ invalid_with_stmt_indent:
964
964
invalid_try_stmt:
965
965
| a='try' ':' NEWLINE !INDENT {
966
966
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
967
+ | 'try' ':' block !('except' | 'finally') { RAISE_SYNTAX_ERROR("expected 'except' or 'finally' block") }
967
968
invalid_except_stmt:
968
969
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
969
970
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
Original file line number Diff line number Diff line change 882
882
Traceback (most recent call last):
883
883
SyntaxError: cannot assign to attribute here. Maybe you meant '==' instead of '='?
884
884
885
+ Custom error messages for try blocks that are not followed by except/finally
886
+
887
+ >>> try:
888
+ ... x = 34
889
+ ...
890
+ Traceback (most recent call last):
891
+ SyntaxError: expected 'except' or 'finally' block
892
+
885
893
Ensure that early = are not matched by the parser as invalid comparisons
886
894
>>> f(2, 4, x=34); 1 $ 2
887
895
Traceback (most recent call last):
Original file line number Diff line number Diff line change
1
+ Improve error message for ``try `` blocks without ``except `` or ``finally ``
2
+ blocks. Patch by Pablo Galindo.
You can’t perform that action at this time.
0 commit comments