Skip to content

Commit 4b85e60

Browse files
authored
bpo-41119: Output correct error message for list/tuple followed by colon (GH-21160)
1 parent 6f8a6ee commit 4b85e60

File tree

2 files changed

+289
-325
lines changed

2 files changed

+289
-325
lines changed

Grammar/python.gram

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,18 +646,18 @@ invalid_named_expression:
646646
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
647647
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
648648
invalid_assignment:
649-
| a=list ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") }
650-
| a=tuple ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
651-
| a=star_named_expression ',' star_named_expressions* ':' {
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") }
651+
| a=star_named_expression ',' star_named_expressions* ':' expression {
652652
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
653-
| a=expression ':' expression ['=' annotated_rhs] {
653+
| a=expression ':' expression {
654654
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") }
655655
| (star_targets '=')* a=star_expressions '=' {
656656
RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) }
657657
| (star_targets '=')* a=yield_expr '=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "assignment to yield expression not possible") }
658658
| a=star_expressions augassign (yield_expr | star_expressions) {
659659
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
660-
a,
660+
a,
661661
"'%s' is an illegal expression for augmented assignment",
662662
_PyPegen_get_expr_name(a)
663663
)}

0 commit comments

Comments
 (0)