[Python-checkins] r75223 - in python/trunk: Lib/test/test_augassign.py Misc/NEWS Python/ast.c

benjamin.peterson python-checkins at python.org
Sat Oct 3 22:23:24 CEST 2009


Author: benjamin.peterson
Date: Sat Oct  3 22:23:24 2009
New Revision: 75223

Log:
#7050 fix a SystemError when using tuple unpacking and augmented assignment

Modified:
   python/trunk/Lib/test/test_augassign.py
   python/trunk/Misc/NEWS
   python/trunk/Python/ast.c

Modified: python/trunk/Lib/test/test_augassign.py
==============================================================================
--- python/trunk/Lib/test/test_augassign.py	(original)
+++ python/trunk/Lib/test/test_augassign.py	Sat Oct  3 22:23:24 2009
@@ -24,6 +24,9 @@
             # 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

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Oct  3 22:23:24 2009
@@ -12,6 +12,9 @@
 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.

Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Sat Oct  3 22:23:24 2009
@@ -2097,6 +2097,19 @@
             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)


More information about the Python-checkins mailing list