summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_augassign.py3
-rw-r--r--Python/ast.c13
2 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_augassign.py b/Lib/test/test_augassign.py
index 8567821..e1b6e27 100644
--- a/Lib/test/test_augassign.py
+++ b/Lib/test/test_augassign.py
@@ -19,6 +19,9 @@ class AugAssignTest(unittest.TestCase):
x /= 2
self.assertEquals(x, 3.0)
+ def test_with_unpacking(self):
+ self.assertRaises(SyntaxError, compile, "x, b += 3", "<test>", "exec")
+
def testInList(self):
x = [2]
x[0] += 1
diff --git a/Python/ast.c b/Python/ast.c
index dfcc8e3..8a35a12 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2115,6 +2115,19 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
return NULL;
if(!set_context(c, expr1, Store, ch))
return NULL;
+ /* set_context checks that most expressions are not the left side.
+ Augmented assignments can only have a name, a subscript, or an
+ attribute on the left, though, so we have to explicitly check for
+ those. */
+ switch (expr1->kind) {
+ case Name_kind:
+ case Attribute_kind:
+ case Subscript_kind:
+ break;
+ default:
+ ast_error(ch, "illegal expression for augmented assignment");
+ return NULL;
+ }
ch = CHILD(n, 2);
if (TYPE(ch) == testlist)