bpo-40769: Allow extra surrounding parentheses for invalid annotated assignment rule (GH-20387)

This commit is contained in:
Batuhan Taskaya 2020-06-27 21:33:08 +03:00 committed by GitHub
parent 6dcbc2422d
commit c8f29ad986
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 284 additions and 207 deletions

View file

@ -646,8 +646,12 @@ invalid_named_expression:
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
invalid_assignment:
| a=list ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") }
| a=tuple ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
| a=invalid_ann_assign_target ':' expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a,
"only single target (not %s) can be annotated",
_PyPegen_get_expr_name(a)
)}
| a=star_named_expression ',' star_named_expressions* ':' expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
| a=expression ':' expression {
@ -661,6 +665,10 @@ invalid_assignment:
"'%s' is an illegal expression for augmented assignment",
_PyPegen_get_expr_name(a)
)}
invalid_ann_assign_target[expr_ty]:
| list
| tuple
| '(' a=invalid_ann_assign_target ')' { a }
invalid_del_stmt:
| 'del' a=star_expressions {
RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) }