Commit 97301a9b authored by Evan Simpson's avatar Evan Simpson

Fix "print >>None" and test it.

parent 935c41c4
...@@ -87,7 +87,7 @@ RestrictionMutator modifies a tree produced by ...@@ -87,7 +87,7 @@ RestrictionMutator modifies a tree produced by
compiler.transformer.Transformer, restricting and enhancing the compiler.transformer.Transformer, restricting and enhancing the
code in various ways before sending it to pycodegen. code in various ways before sending it to pycodegen.
''' '''
__version__='$Revision: 1.3 $'[11:-2] __version__='$Revision: 1.4 $'[11:-2]
from compiler import ast from compiler import ast
from compiler.transformer import parse from compiler.transformer import parse
...@@ -213,9 +213,11 @@ class RestrictionMutator: ...@@ -213,9 +213,11 @@ class RestrictionMutator:
def visitPrint(self, node, walker): def visitPrint(self, node, walker):
node = walker.defaultVisitNode(node) node = walker.defaultVisitNode(node)
self.funcinfo._print_used = 1
if node.dest is None: if node.dest is None:
self.funcinfo._print_used = 1
node.dest = _print_target_name node.dest = _print_target_name
else:
node.dest = ast.Or([node.dest, _print_target_name])
return node return node
visitPrintnl = visitPrint visitPrintnl = visitPrint
......
def print1(): def print0():
print 'Hello, world!', print 'Hello, world!',
return printed return printed
def print1():
print 'Hello,',
print 'world!',
return printed
def print2():
x = None
print >>x, 'Hello, world!',
return printed
def primes(): def primes():
# Somewhat obfuscated code on purpose # Somewhat obfuscated code on purpose
print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0, print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,
......
...@@ -170,8 +170,9 @@ class RestrictionTests(unittest.TestCase): ...@@ -170,8 +170,9 @@ class RestrictionTests(unittest.TestCase):
return func(*args, **kw) return func(*args, **kw)
def checkPrint(self): def checkPrint(self):
res = self.execFunc('print1') for i in range(3):
assert res == 'Hello, world!', res res = self.execFunc('print%s' % i)
assert res == 'Hello, world!', res
def checkPrimes(self): def checkPrimes(self):
res = self.execFunc('primes') res = self.execFunc('primes')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment