Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e4cc7e

Browse files
committed
Last set of change to get regression tests to pass
Remove the only test in the syntax module. It ends up that the transformer must handle this error case. In the transformer, check for a list compression in com_assign_list() by looking for a list_for node where a comma is expected. In pycodegen.compile() re-raise the SyntaxError rather than catching it and exiting
1 parent c299fc1 commit 2e4cc7e

6 files changed

Lines changed: 20 additions & 10 deletions

File tree

Lib/compiler/pycodegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def compile(filename, display=0):
4949
try:
5050
mod.compile(display)
5151
except SyntaxError, err:
52-
print "SyntaxError:", err
52+
raise
5353
else:
5454
f = open(filename + "c", "wb")
5555
mod.dump(f)

Lib/compiler/syntax.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def error(self, node, msg):
3939
def visitAssign(self, node):
4040
# the transformer module handles many of these
4141
for target in node.nodes:
42-
if isinstance(target, ast.AssList):
43-
if target.lineno is None:
44-
target.lineno = node.lineno
45-
self.error(target, "can't assign to list comprehension")
42+
pass
43+
## if isinstance(target, ast.AssList):
44+
## if target.lineno is None:
45+
## target.lineno = node.lineno
46+
## self.error(target, "can't assign to list comprehension")

Lib/compiler/transformer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,10 @@ def com_assign_tuple(self, node, assigning):
943943
def com_assign_list(self, node, assigning):
944944
assigns = []
945945
for i in range(1, len(node), 2):
946+
if i + 1 < len(node):
947+
if node[i + 1][0] == symbol.list_for:
948+
raise SyntaxError, "can't assign to list comprehension"
949+
assert node[i + 1][0] == token.COMMA, node[i + 1]
946950
assigns.append(self.com_assign(node[i], assigning))
947951
return AssList(assigns)
948952

Tools/compiler/compiler/pycodegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def compile(filename, display=0):
4949
try:
5050
mod.compile(display)
5151
except SyntaxError, err:
52-
print "SyntaxError:", err
52+
raise
5353
else:
5454
f = open(filename + "c", "wb")
5555
mod.dump(f)

Tools/compiler/compiler/syntax.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def error(self, node, msg):
3939
def visitAssign(self, node):
4040
# the transformer module handles many of these
4141
for target in node.nodes:
42-
if isinstance(target, ast.AssList):
43-
if target.lineno is None:
44-
target.lineno = node.lineno
45-
self.error(target, "can't assign to list comprehension")
42+
pass
43+
## if isinstance(target, ast.AssList):
44+
## if target.lineno is None:
45+
## target.lineno = node.lineno
46+
## self.error(target, "can't assign to list comprehension")

Tools/compiler/compiler/transformer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,10 @@ def com_assign_tuple(self, node, assigning):
943943
def com_assign_list(self, node, assigning):
944944
assigns = []
945945
for i in range(1, len(node), 2):
946+
if i + 1 < len(node):
947+
if node[i + 1][0] == symbol.list_for:
948+
raise SyntaxError, "can't assign to list comprehension"
949+
assert node[i + 1][0] == token.COMMA, node[i + 1]
946950
assigns.append(self.com_assign(node[i], assigning))
947951
return AssList(assigns)
948952

0 commit comments

Comments
 (0)