r52882 - sandbox/trunk/2to3/example.py sandbox/trunk/2to3/fix_print.py sandbox/trunk/2to3/pytree.py
![](https://secure.gravatar.com/avatar/8ac615df352a970211b0e3d94a307c6d.jpg?s=120&d=mm&r=g)
Author: guido.van.rossum Date: Fri Dec 1 01:21:41 2006 New Revision: 52882 Modified: sandbox/trunk/2to3/example.py sandbox/trunk/2to3/fix_print.py sandbox/trunk/2to3/pytree.py Log: Refactoring tool for apply(). Modified: sandbox/trunk/2to3/example.py ============================================================================== --- sandbox/trunk/2to3/example.py (original) +++ sandbox/trunk/2to3/example.py Fri Dec 1 01:21:41 2006 @@ -11,6 +11,13 @@ def foo(): pass # body indented by tab +def apply_examples(): + x = apply(f, g + h) + y = apply(f, g, h) + z = apply(fs[0], g or h, h or g) + # Hello + apply(f, (x, y) + t) + def print_examples(): # plain vanilla print 1, 1+1, 1+1+1 Modified: sandbox/trunk/2to3/fix_print.py ============================================================================== --- sandbox/trunk/2to3/fix_print.py (original) +++ sandbox/trunk/2to3/fix_print.py Fri Dec 1 01:21:41 2006 @@ -57,7 +57,6 @@ def fix_print(node): if node.type != syms.print_stmt: return - print "Bingo! >>>%s<<<" % node assert node.children[0] == pytree.Leaf(token.NAME, "print") args = node.children[1:] sep = end = file = None @@ -93,7 +92,6 @@ n_trailer = pytree.Node(syms.trailer, l_args) n_stmt = pytree.Node(syms.power, (n_print, n_trailer)) n_stmt.set_prefix(node.get_prefix()) - print "Synthesized: >>>%s<<<" % n_stmt node.replace(n_stmt) Modified: sandbox/trunk/2to3/pytree.py ============================================================================== --- sandbox/trunk/2to3/pytree.py (original) +++ sandbox/trunk/2to3/pytree.py Fri Dec 1 01:21:41 2006 @@ -51,9 +51,9 @@ ch.parent = self def __repr__(self): - return "%s(<>, %r, %r)" % (self.__class__.__name__, - self.type, - self.children) + return "%s(%r, %r)" % (self.__class__.__name__, + self.type, + self.children) def __str__(self): return "".join(str(ch) for ch in self.children) @@ -104,9 +104,9 @@ self.value = value def __repr__(self): - return "%s(<>, %r, %r)" % (self.__class__.__name__, - self.type, - self.value) + return "%s(%r, %r)" % (self.__class__.__name__, + self.type, + self.value) def __str__(self): return self.prefix + self.value @@ -124,6 +124,8 @@ def convert(gr, raw_node): type, value, context, children = raw_node if children or type in gr.number2symbol: + # XXX If there's exactly one child, should return that child + # instead of synthesizing a new node. return Node(type, children, context=context) else: return Leaf(type, value, context=context)
participants (1)
-
guido.van.rossum