Skip to content

Commit

Permalink
bpo-35814: Allow unpacking in r.h.s of annotated assignment expressio…
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogsal authored Jun 3, 2019
1 parent d9677f3 commit 8565f6b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Grammar/Grammar
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
[('=' (yield_expr|testlist_star_expr))+ [TYPE_COMMENT]] )
annassign: ':' test ['=' (yield_expr|testlist)]
annassign: ':' test ['=' (yield_expr|testlist_star_expr)]
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ def test_var_annot_rhs(self):
exec(stmt, ns)
self.assertEqual(list(ns['f']()), [None])

ns = {"a": 1, 'b': (2, 3, 4), "c":5, "Tuple": typing.Tuple}
exec('x: Tuple[int, ...] = a,*b,c', ns)
self.assertEqual(ns['x'], (1, 2, 3, 4, 5))

def test_funcdef(self):
### [decorators] 'def' NAME parameters ['->' test] ':' suite
### decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow unpacking in the right hand side of annotated assignments. In
particular, ``t: Tuple[int, ...] = x, y, *z`` is now allowed.
2 changes: 1 addition & 1 deletion Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3398,7 +3398,7 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
}
else {
ch = CHILD(ann, 3);
if (TYPE(ch) == testlist) {
if (TYPE(ch) == testlist_star_expr) {
expr3 = ast_for_testlist(c, ch);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion Python/graminit.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ static const arc arcs_17_2[2] = {
{0, 2},
};
static const arc arcs_17_3[2] = {
{47, 4},
{81, 4},
{84, 4},
};
static const arc arcs_17_4[1] = {
Expand Down

0 comments on commit 8565f6b

Please sign in to comment.