[Python-checkins] r52879 - sandbox/trunk/2to3/fix_has_key.py sandbox/trunk/2to3/play.py sandbox/trunk/2to3/pytree.py
guido.van.rossum
python-checkins at python.org
Thu Nov 30 23:52:41 CET 2006
Author: guido.van.rossum
Date: Thu Nov 30 23:52:40 2006
New Revision: 52879
Modified:
sandbox/trunk/2to3/fix_has_key.py
sandbox/trunk/2to3/play.py
sandbox/trunk/2to3/pytree.py
Log:
Change node constructor signatures so context is an optional keyword argument.
Modified: sandbox/trunk/2to3/fix_has_key.py
==============================================================================
--- sandbox/trunk/2to3/fix_has_key.py (original)
+++ sandbox/trunk/2to3/fix_has_key.py Thu Nov 30 23:52:40 2006
@@ -49,13 +49,13 @@
visit(child, func)
# Sample nodes
-n_dot = pytree.Leaf(None, token.DOT, ".")
-n_has_key = pytree.Leaf(None, token.NAME, "has_key")
-n_trailer_has_key = pytree.Node(None, syms.trailer, (n_dot, n_has_key))
-n_lpar = pytree.Leaf(None, token.LPAR, "(")
-n_star = pytree.Leaf(None, token.STAR, "*")
-n_comma = pytree.Leaf(None, token.COMMA, ",")
-n_in = pytree.Leaf((" ", (0, 0)), token.NAME, "in") # XXX what operator?
+n_dot = pytree.Leaf(token.DOT, ".")
+n_has_key = pytree.Leaf(token.NAME, "has_key")
+n_trailer_has_key = pytree.Node(syms.trailer, (n_dot, n_has_key))
+n_lpar = pytree.Leaf(token.LPAR, "(")
+n_star = pytree.Leaf(token.STAR, "*")
+n_comma = pytree.Leaf(token.COMMA, ",")
+n_in = pytree.Leaf(token.NAME, "in", context=(" ", (0, 0)))
import pdb
@@ -98,8 +98,8 @@
# Change "X.has_key(Y)" into "Y in X"
arg.set_prefix(nodes[0].get_prefix())
nodes[0].set_prefix(" ")
- new = pytree.Node(None, syms.comparison,
- (arg, n_in, pytree.Node(None, syms.power, nodes[:i])))
+ new = pytree.Node(syms.comparison,
+ (arg, n_in, pytree.Node(syms.power, nodes[:i])))
# XXX Sometimes we need to parenthesize arg or new. Later.
parent.parent.replace(parent, new)
Modified: sandbox/trunk/2to3/play.py
==============================================================================
--- sandbox/trunk/2to3/play.py (original)
+++ sandbox/trunk/2to3/play.py Thu Nov 30 23:52:40 2006
@@ -27,7 +27,8 @@
sys.stdout.write(str(tree))
if not diff(fn, tree):
print "No diffs."
- return # Comment out to run the complete test suite below
+ if not sys.argv[1:]:
+ return # Pass a dummy argument to run the complete test suite below
problems = []
Modified: sandbox/trunk/2to3/pytree.py
==============================================================================
--- sandbox/trunk/2to3/pytree.py (original)
+++ sandbox/trunk/2to3/pytree.py Thu Nov 30 23:52:40 2006
@@ -18,9 +18,9 @@
parent = None
children = ()
- def __new__(cls, *rest):
+ def __new__(cls, *args, **kwds):
assert cls is not Base, "Cannot instantiate Base"
- return object.__new__(cls, *rest)
+ return object.__new__(cls, *args, **kwds)
def __eq__(self, other):
if self.__class__ is not other.__class__:
@@ -44,7 +44,7 @@
class Node(Base):
- def __init__(self, context, type, children):
+ def __init__(self, type, children, context=None):
self.type = type
self.children = tuple(children)
for ch in self.children:
@@ -82,12 +82,13 @@
l_children.append(ch)
assert found, (self.children, old, new)
self.children = tuple(l_children)
+ new.parent = self
class Leaf(Base):
- def __init__(self, context, type, value):
- if context:
+ def __init__(self, type, value, context=None):
+ if context is not None:
self.prefix, (self.lineno, self.column) = context
else:
self.prefix = ""
@@ -116,6 +117,6 @@
def convert(gr, raw_node):
type, value, context, children = raw_node
if children or type in gr.number2symbol:
- return Node(context, type, children)
+ return Node(type, children, context=context)
else:
- return Leaf(context, type, value)
+ return Leaf(type, value, context=context)
More information about the Python-checkins
mailing list