Skip to content

Commit d01a3e7

Browse files
authored
[3.9] bpo-41119: Output correct error message for list/tuple followed by colon (GH-21160) (GH-21172)
(cherry picked from commit 4b85e60)
1 parent f925407 commit d01a3e7

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
@@ -648,18 +648,18 @@ invalid_named_expression:
648648
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
649649
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
650650
invalid_assignment:
651-
| a=list ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") }
652-
| a=tuple ':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
653-
| a=star_named_expression ',' star_named_expressions* ':' {
651+
| a=list ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") }
652+
| a=tuple ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
653+
| a=star_named_expression ',' star_named_expressions* ':' expression {
654654
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
655-
| a=expression ':' expression ['=' annotated_rhs] {
655+
| a=expression ':' expression {
656656
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") }
657657
| (star_targets '=')* a=star_expressions '=' {
658658
RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) }
659659
| (star_targets '=')* a=yield_expr '=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "assignment to yield expression not possible") }
660660
| a=star_expressions augassign (yield_expr | star_expressions) {
661661
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
662-
a,
662+
a,
663663
"'%s' is an illegal expression for augmented assignment",
664664
_PyPegen_get_expr_name(a)
665665
)}

0 commit comments

Comments
 (0)