Skip to content

Commit 7adbb5a

Browse files
committed
#7050 fix a SystemError when using tuple unpacking and augmented assignment
1 parent 3b34dd8 commit 7adbb5a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Lib/test/test_augassign.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def testBasic(self):
2424
# new-style division (with -Qnew)
2525
self.assertEquals(x, 3.0)
2626

27+
def test_with_unpacking(self):
28+
self.assertRaises(SyntaxError, compile, "x, b += 3", "<test>", "exec")
29+
2730
def testInList(self):
2831
x = [2]
2932
x[0] += 1

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #7050: Fix a SystemError when trying to use unpacking and augmented
16+
assignment.
17+
1518
- Issue #5329: Fix os.popen* regression from 2.5 with commands as a
1619
sequence running through the shell. Patch by Jean-Paul Calderone
1720
and Jani Hakala.

Python/ast.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,19 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
20972097
return NULL;
20982098
if(!set_context(c, expr1, Store, ch))
20992099
return NULL;
2100+
/* set_context checks that most expressions are not the left side.
2101+
Augmented assignments can only have a name, a subscript, or an
2102+
attribute on the left, though, so we have to explicitly check for
2103+
those. */
2104+
switch (expr1->kind) {
2105+
case Name_kind:
2106+
case Attribute_kind:
2107+
case Subscript_kind:
2108+
break;
2109+
default:
2110+
ast_error(ch, "illegal expression for augmented assignment");
2111+
return NULL;
2112+
}
21002113

21012114
ch = CHILD(n, 2);
21022115
if (TYPE(ch) == testlist)

0 commit comments

Comments
 (0)