File tree Expand file tree Collapse file tree 4 files changed +262
-173
lines changed
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree 4 files changed +262
-173
lines changed Original file line number Diff line number Diff line change @@ -1315,6 +1315,14 @@ invalid_assert_stmt:
1315
1315
a, b,
1316
1316
"cannot assign to %s here. Maybe you meant '==' instead of '='?",
1317
1317
_PyPegen_get_expr_name(a)) }
1318
+ | 'assert' a=expression ':=' b=expression {
1319
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(
1320
+ a, b,
1321
+ "cannot use named expression without parentheses here") }
1322
+ | 'assert' expression ',' a=expression ':=' b=expression {
1323
+ RAISE_SYNTAX_ERROR_KNOWN_RANGE(
1324
+ a, b,
1325
+ "cannot use named expression without parentheses here") }
1318
1326
invalid_block:
1319
1327
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
1320
1328
invalid_comprehension:
Original file line number Diff line number Diff line change @@ -2690,10 +2690,15 @@ def f(x: *b)
2690
2690
Asserts:
2691
2691
2692
2692
>>> assert (a := 1) # ok
2693
- >>> # TODO(@sobolevn): improve this message in the next PR
2693
+ >>> assert 1, (a := 1) # ok
2694
+
2694
2695
>>> assert a := 1
2695
2696
Traceback (most recent call last):
2696
- SyntaxError: invalid syntax
2697
+ SyntaxError: cannot use named expression without parentheses here
2698
+
2699
+ >>> assert 1, a := 1
2700
+ Traceback (most recent call last):
2701
+ SyntaxError: cannot use named expression without parentheses here
2697
2702
2698
2703
>>> assert 1 = 2 = 3
2699
2704
Traceback (most recent call last):
Original file line number Diff line number Diff line change
1
+ Improve :exc: `SyntaxError ` message for :keyword: `assert ` in cases like
2
+ ``assert a := b ``.
You can’t perform that action at this time.
0 commit comments