]> granicus.if.org Git - python/commitdiff
#7050 fix a SystemError when using tuple unpacking and augmented assignment
authorBenjamin Peterson <benjamin@python.org>
Sat, 3 Oct 2009 20:23:24 +0000 (20:23 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 3 Oct 2009 20:23:24 +0000 (20:23 +0000)
Lib/test/test_augassign.py
Misc/NEWS
Python/ast.c

index 24aa2b7c9e3286c86ec970710f32c74657cc9e05..a5b7cc4aaa0362c82169c5534abf95b109f0bc83 100644 (file)
@@ -24,6 +24,9 @@ class AugAssignTest(unittest.TestCase):
             # new-style division (with -Qnew)
             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 dc54329db9a08eaf12b67d22418d3d298fd0f427..bafb0ab5d1563c5161cce22c3dad0014be129fab 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
 Core and Builtins
 -----------------
 
+- Issue #7050: Fix a SystemError when trying to use unpacking and augmented
+  assignment.
+
 - Issue #5329: Fix os.popen* regression from 2.5 with commands as a
   sequence running through the shell.  Patch by Jean-Paul Calderone
   and Jani Hakala.
index 2f975ac8e0a286c9155eee6b92870195432c8955..3422c2e1b0dd51d714898b5ffb8ada59829139b3 100644 (file)
@@ -2097,6 +2097,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)