import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*)
-annassign: ':' test ['=' test]
+annassign: ':' test ['=' (yield_expr|testlist)]
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
exec('X: str', {}, CNS2())
self.assertEqual(nonloc_ns['__annotations__']['x'], str)
+ def test_var_annot_rhs(self):
+ ns = {}
+ exec('x: tuple = 1, 2', ns)
+ self.assertEqual(ns['x'], (1, 2))
+ stmt = ('def f():\n'
+ ' x: int = yield')
+ exec(stmt, ns)
+ self.assertEqual(list(ns['f']()), [None])
+
def test_funcdef(self):
### [decorators] 'def' NAME parameters ['->' test] ':' suite
### decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
with self.assertRaises(SyntaxError):
exec("x, *y, z: int = range(5)", {}, {})
with self.assertRaises(SyntaxError):
- exec("t: tuple = 1, 2", {}, {})
+ exec("x: int = 1, y = 2", {}, {})
with self.assertRaises(SyntaxError):
exec("u = v: int", {}, {})
with self.assertRaises(SyntaxError):
--- /dev/null
+Allow same right hand side expressions in annotated assignments as in normal ones.\r
+In particular, ``x: Tuple[int, int] = 1, 2`` (without parentheses on the right) is now allowed.
\ No newline at end of file
}
else {
ch = CHILD(ann, 3);
- expr3 = ast_for_expr(c, ch);
+ if (TYPE(ch) == testlist) {
+ expr3 = ast_for_testlist(c, ch);
+ }
+ else {
+ expr3 = ast_for_expr(c, ch);
+ }
if (!expr3) {
return NULL;
}
{31, 3},
{0, 2},
};
-static arc arcs_17_3[1] = {
- {26, 4},
+static arc arcs_17_3[2] = {
+ {50, 4},
+ {9, 4},
};
static arc arcs_17_4[1] = {
{0, 4},
{1, arcs_17_0},
{1, arcs_17_1},
{2, arcs_17_2},
- {1, arcs_17_3},
+ {2, arcs_17_3},
{1, arcs_17_4},
};
static arc arcs_18_0[2] = {