Skip to content

Commit 8565f6b

Browse files
authored
bpo-35814: Allow unpacking in r.h.s of annotated assignment expressions (GH-13760)
1 parent d9677f3 commit 8565f6b

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

Grammar/Grammar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
8484
import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
8585
expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
8686
[('=' (yield_expr|testlist_star_expr))+ [TYPE_COMMENT]] )
87-
annassign: ':' test ['=' (yield_expr|testlist)]
87+
annassign: ':' test ['=' (yield_expr|testlist_star_expr)]
8888
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
8989
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
9090
'<<=' | '>>=' | '**=' | '//=')

Lib/test/test_grammar.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ def test_var_annot_rhs(self):
454454
exec(stmt, ns)
455455
self.assertEqual(list(ns['f']()), [None])
456456

457+
ns = {"a": 1, 'b': (2, 3, 4), "c":5, "Tuple": typing.Tuple}
458+
exec('x: Tuple[int, ...] = a,*b,c', ns)
459+
self.assertEqual(ns['x'], (1, 2, 3, 4, 5))
460+
457461
def test_funcdef(self):
458462
### [decorators] 'def' NAME parameters ['->' test] ':' suite
459463
### decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allow unpacking in the right hand side of annotated assignments. In
2+
particular, ``t: Tuple[int, ...] = x, y, *z`` is now allowed.

Python/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
33983398
}
33993399
else {
34003400
ch = CHILD(ann, 3);
3401-
if (TYPE(ch) == testlist) {
3401+
if (TYPE(ch) == testlist_star_expr) {
34023402
expr3 = ast_for_testlist(c, ch);
34033403
}
34043404
else {

Python/graminit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ static const arc arcs_17_2[2] = {
742742
{0, 2},
743743
};
744744
static const arc arcs_17_3[2] = {
745-
{47, 4},
745+
{81, 4},
746746
{84, 4},
747747
};
748748
static const arc arcs_17_4[1] = {

0 commit comments

Comments
 (0)