File tree Expand file tree Collapse file tree 3 files changed +284
-207
lines changed
Expand file tree Collapse file tree 3 files changed +284
-207
lines changed Original file line number Diff line number Diff line change @@ -646,8 +646,12 @@ invalid_named_expression:
646646 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
647647 a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
648648invalid_assignment:
649- | a=list ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") }
650- | a=tuple ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
649+ | a=invalid_ann_assign_target ':' expression {
650+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
651+ a,
652+ "only single target (not %s) can be annotated",
653+ _PyPegen_get_expr_name(a)
654+ )}
651655 | a=star_named_expression ',' star_named_expressions* ':' expression {
652656 RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
653657 | a=expression ':' expression {
@@ -661,6 +665,10 @@ invalid_assignment:
661665 "'%s' is an illegal expression for augmented assignment",
662666 _PyPegen_get_expr_name(a)
663667 )}
668+ invalid_ann_assign_target[expr_ty]:
669+ | list
670+ | tuple
671+ | '(' a=invalid_ann_assign_target ')' { a }
664672invalid_del_stmt:
665673 | 'del' a=star_expressions {
666674 RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) }
Original file line number Diff line number Diff line change 733733Traceback (most recent call last):
734734SyntaxError: trailing comma not allowed without surrounding parentheses
735735
736+ >>> (): int
737+ Traceback (most recent call last):
738+ SyntaxError: only single target (not tuple) can be annotated
739+ >>> []: int
740+ Traceback (most recent call last):
741+ SyntaxError: only single target (not list) can be annotated
742+ >>> (()): int
743+ Traceback (most recent call last):
744+ SyntaxError: only single target (not tuple) can be annotated
745+ >>> ([]): int
746+ Traceback (most recent call last):
747+ SyntaxError: only single target (not list) can be annotated
748+
736749Corner-cases that used to fail to raise the correct error:
737750
738751 >>> def f(*, x=lambda __debug__:0): pass
You can’t perform that action at this time.
0 commit comments