Skip to content

Commit 4fac706

Browse files
committed
Merged revisions 75224 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r75224 | benjamin.peterson | 2009-10-03 15:27:13 -0500 (Sat, 03 Oct 2009) | 9 lines Merged revisions 75223 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75223 | benjamin.peterson | 2009-10-03 15:23:24 -0500 (Sat, 03 Oct 2009) | 1 line #7050 fix a SystemError when using tuple unpacking and augmented assignment ........ ................
1 parent 01c5496 commit 4fac706

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Lib/test/test_augassign.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def testBasic(self):
1919
x /= 2
2020
self.assertEquals(x, 3.0)
2121

22+
def test_with_unpacking(self):
23+
self.assertRaises(SyntaxError, compile, "x, b += 3", "<test>", "exec")
24+
2225
def testInList(self):
2326
x = [2]
2427
x[0] += 1

Python/ast.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,19 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
21052105
return NULL;
21062106
if(!set_context(c, expr1, Store, ch))
21072107
return NULL;
2108+
/* set_context checks that most expressions are not the left side.
2109+
Augmented assignments can only have a name, a subscript, or an
2110+
attribute on the left, though, so we have to explicitly check for
2111+
those. */
2112+
switch (expr1->kind) {
2113+
case Name_kind:
2114+
case Attribute_kind:
2115+
case Subscript_kind:
2116+
break;
2117+
default:
2118+
ast_error(ch, "illegal expression for augmented assignment");
2119+
return NULL;
2120+
}
21082121

21092122
ch = CHILD(n, 2);
21102123
if (TYPE(ch) == testlist)

0 commit comments

Comments
 (0)