]> granicus.if.org Git - python/commitdiff
Merged revisions 75224 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 3 Oct 2009 20:28:47 +0000 (20:28 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 3 Oct 2009 20:28:47 +0000 (20:28 +0000)
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
  ........
................

Lib/test/test_augassign.py
Python/ast.c

index 8567821c886872e16d0ed6d6953e8600a37c1b6b..e1b6e2712177169707d11d4194f7b7756a29149a 100644 (file)
@@ -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
index 83572ee882150e97e1190a14ce4f26847ce04708..b0684c57304782204688ebe173daa9b5d11e08e1 100644 (file)
@@ -2105,6 +2105,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)