Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd27aef

Browse files
committed
Merged revisions 75223 via svnmerge from
svn+ssh://[email protected]/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 8504d08 commit bd27aef

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
@@ -2115,6 +2115,19 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
21152115
return NULL;
21162116
if(!set_context(c, expr1, Store, ch))
21172117
return NULL;
2118+
/* set_context checks that most expressions are not the left side.
2119+
Augmented assignments can only have a name, a subscript, or an
2120+
attribute on the left, though, so we have to explicitly check for
2121+
those. */
2122+
switch (expr1->kind) {
2123+
case Name_kind:
2124+
case Attribute_kind:
2125+
case Subscript_kind:
2126+
break;
2127+
default:
2128+
ast_error(ch, "illegal expression for augmented assignment");
2129+
return NULL;
2130+
}
21182131

21192132
ch = CHILD(n, 2);
21202133
if (TYPE(ch) == testlist)

0 commit comments

Comments
 (0)