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
compiler.transformer.Transformer, restricting and enhancing the
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.transformer import parse
......@@ -213,9 +213,11 @@ class RestrictionMutator:
def visitPrint(self, node, walker):
node = walker.defaultVisitNode(node)
self.funcinfo._print_used = 1
if node.dest is None:
self.funcinfo._print_used = 1
node.dest = _print_target_name
else:
node.dest = ast.Or([node.dest, _print_target_name])
return node
visitPrintnl = visitPrint
......
def print1():
def print0():
print 'Hello, world!',
return printed
def print1():
print 'Hello,',
print 'world!',
return printed
def print2():
x = None
print >>x, 'Hello, world!',
return printed
def primes():
# Somewhat obfuscated code on purpose
print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,
......
......@@ -170,8 +170,9 @@ class RestrictionTests(unittest.TestCase):
return func(*args, **kw)
def checkPrint(self):
res = self.execFunc('print1')
assert res == 'Hello, world!', res
for i in range(3):
res = self.execFunc('print%s' % i)
assert res == 'Hello, world!', res
def checkPrimes(self):
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